summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <dontpanic@binaryninja.com>2015-03-19 03:05:26 -0400
committerRusty Wagner <dontpanic@binaryninja.com>2015-03-19 03:05:26 -0400
commit97cbee81fcda2a812cc655cc6b8cf1e2bead67b9 (patch)
treef920aac8d39086c39d52db3853f13182179a53b1
parentc4508b572c4e6b17bae49953bb6a6cceac043a95 (diff)
Improve performance by avoiding heavy lock contention
-rw-r--r--binaryninjaapi.h3
-rw-r--r--log.cpp14
2 files changed, 17 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index c986ac77..ed2d2cec 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -128,15 +128,18 @@ namespace BinaryNinja
{
static void LogMessageCallback(void* ctxt, BNLogLevel level, const char* msg);
static void CloseLogCallback(void* ctxt);
+ static BNLogLevel GetLogLevelCallback(void* ctxt);
public:
virtual ~LogListener() {}
static void RegisterLogListener(LogListener* listener);
static void UnregisterLogListener(LogListener* listener);
+ static void UpdateLogListeners();
virtual void LogMessage(BNLogLevel level, const std::string& msg) = 0;
virtual void CloseLog() {}
+ virtual BNLogLevel GetLogLevel() { return WarningLog; }
};
void Log(BNLogLevel level, const char* fmt, ...);
diff --git a/log.cpp b/log.cpp
index 7687a190..4b271a0f 100644
--- a/log.cpp
+++ b/log.cpp
@@ -21,12 +21,20 @@ void LogListener::CloseLogCallback(void* ctxt)
}
+BNLogLevel LogListener::GetLogLevelCallback(void* ctxt)
+{
+ LogListener* listener = (LogListener*)ctxt;
+ return listener->GetLogLevel();
+}
+
+
void LogListener::RegisterLogListener(LogListener* listener)
{
BNLogListener callbacks;
callbacks.context = listener;
callbacks.log = LogMessageCallback;
callbacks.close = CloseLogCallback;
+ callbacks.getLogLevel = GetLogLevelCallback;
BNRegisterLogListener(&callbacks);
}
@@ -41,6 +49,12 @@ void LogListener::UnregisterLogListener(LogListener* listener)
}
+void LogListener::UpdateLogListeners()
+{
+ BNUpdateLogListeners();
+}
+
+
static void PerformLog(BNLogLevel level, const char* fmt, va_list args)
{
#if defined(_MSC_VER)