Fix thread-safe behaviour
This commit is contained in:
parent
799c9c4218
commit
07539f7985
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
using namespace sc;
|
using namespace sc;
|
||||||
|
|
||||||
std::mutex logger::_mtx;
|
std::recursive_mutex logger::_mtx;
|
||||||
|
|
||||||
logger::logger(const std::string& name, loglevel level)
|
logger::logger(const std::string& name, loglevel level)
|
||||||
: _level(level), _name(name) {}
|
: _level(level), _name(name) {}
|
||||||
@ -15,7 +15,6 @@ logger::logger(const std::string& name, loglevel level)
|
|||||||
void logger::msg(loglevel level, const sc::io::trgb* color,
|
void logger::msg(loglevel level, const sc::io::trgb* color,
|
||||||
const char* file, int line, const char* func) {
|
const char* file, int line, const char* func) {
|
||||||
if (level >= _level) {
|
if (level >= _level) {
|
||||||
std::lock_guard<std::mutex> lock {_mtx};
|
|
||||||
if (_topcall) {
|
if (_topcall) {
|
||||||
write_prefix(level, color, file, line, func);
|
write_prefix(level, color, file, line, func);
|
||||||
} else {
|
} else {
|
||||||
|
@ -45,6 +45,7 @@ namespace sc {
|
|||||||
const char* file, int line, const char* func,
|
const char* file, int line, const char* func,
|
||||||
T value, Args... args) {
|
T value, Args... args) {
|
||||||
if (level >= _level) {
|
if (level >= _level) {
|
||||||
|
std::lock_guard<std::recursive_mutex> lock {_mtx};
|
||||||
if (_topcall) {
|
if (_topcall) {
|
||||||
_topcall = false;
|
_topcall = false;
|
||||||
write_prefix(level, color, file, line, func);
|
write_prefix(level, color, file, line, func);
|
||||||
@ -67,7 +68,7 @@ namespace sc {
|
|||||||
loglevel _level {loglevel::info};
|
loglevel _level {loglevel::info};
|
||||||
bool _topcall {true};
|
bool _topcall {true};
|
||||||
std::string _name;
|
std::string _name;
|
||||||
static std::mutex _mtx;
|
static std::recursive_mutex _mtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user