Skip to content

Commit

Permalink
Using log queue
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Jan 21, 2025
1 parent 4759dcd commit c5e837a
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions EdiabasLib/Api32/ApiDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ref class GlobalObjects
public:
static List<Ediabas::ApiInternal ^>^ handles = gcnew List<Ediabas::ApiInternal ^>();
static Object ^ handleLock = gcnew Object();
static Text::StringBuilder^ logBuffer = gcnew Text::StringBuilder();
static Queue<String^>^ logQueue = gcnew Queue<String^>();
static Object^ logLock = gcnew Object();

static GlobalObjects()
Expand Down Expand Up @@ -245,22 +245,29 @@ ref class GlobalObjects

if (apiInternal != nullptr)
{
String^ logText = nullptr;
try
do
{
Monitor::Enter(logLock);
logText = logBuffer->ToString();
logBuffer->Clear();
}
finally
{
Monitor::Exit(logLock);
}
String^ logText = nullptr;
try
{
Monitor::Enter(logLock);
if (logQueue->Count > 0)
{
logText = logQueue->Dequeue();
}
}
finally
{
Monitor::Exit(logLock);
}

if (String::IsNullOrEmpty(logText))
{
break;
}

if (!String::IsNullOrEmpty(logText))
{
apiInternal->logString(Ediabas::ApiInternal::ApiLogLevel::Normal, logText);
}
} while (true);
}

return apiInternal;
Expand Down Expand Up @@ -1274,9 +1281,9 @@ static void LogExternal(const char far* prefix, const char far* text)
{
try
{
String^ logText = "External (" + ConvertCString(prefix) + "): " + ConvertCString(text);
String^ logText = "External [" + ConvertCString(prefix) + "]: " + ConvertCString(text);
Monitor::Enter(GlobalObjects::logLock);
GlobalObjects::logBuffer->AppendLine(logText);
GlobalObjects::logQueue->Enqueue(logText);
}
finally
{
Expand Down

0 comments on commit c5e837a

Please sign in to comment.