Skip to content

Commit

Permalink
[BUGFIX] Use one std mutex (defined in term_util)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jun 9, 2024
1 parent 35ecefa commit 3962e29
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion etw_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mutex>

#include "util/process_util.h"
#include "term_util.h"

#if (_MSC_VER >= 1900)

Expand Down Expand Up @@ -59,7 +60,6 @@ struct ProceesStat
};

ProceesStat procStats[MAX_PROCESSES] = { 0 };
std::mutex g_stdOutMutex;

// ETW Handler
// To filter our events, we want to compare against the
Expand Down
5 changes: 3 additions & 2 deletions term_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string>
#include <mutex>

std::mutex g_stdOutMutex;

bool get_current_color(int descriptor, WORD &color)
{
CONSOLE_SCREEN_BUFFER_INFO info;
Expand All @@ -30,8 +32,7 @@ WORD set_color(WORD color)

void print_in_color(WORD color, const std::string &text)
{
static std::mutex colorOutMtx;
const std::lock_guard<std::mutex> stdOutLock(colorOutMtx);
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
WORD old_color = set_color(color);
std::cout << text;
std::cout.flush();
Expand Down
3 changes: 3 additions & 0 deletions term_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <iostream>
#include <windows.h>
#include <mutex>

extern std::mutex g_stdOutMutex;

#define BLACK 0
#define DARK_BLUE 1
Expand Down

0 comments on commit 3962e29

Please sign in to comment.