Skip to content

Commit

Permalink
[core] Apply logger lock on its config.
Browse files Browse the repository at this point in the history
Co-authored-by: Sektor van Skijlen <ethouris@gmail.com>
  • Loading branch information
maxsharabayko and ethouris committed Aug 13, 2024
1 parent cf4b080 commit f7b32e7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions srtcore/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct LogConfig
std::ostream* log_stream;
SRT_LOG_HANDLER_FN* loghandler_fn;
void* loghandler_opaque;
srt::sync::Mutex mutex;
mutable srt::sync::Mutex mutex;
int flags;

LogConfig(const fa_bitset_t& efa,
Expand All @@ -132,10 +132,10 @@ struct LogConfig
}

SRT_ATTR_ACQUIRE(mutex)
void lock() { mutex.lock(); }
void lock() const { mutex.lock(); }

SRT_ATTR_RELEASE(mutex)
void unlock() { mutex.unlock(); }
void unlock() const { mutex.unlock(); }
};

// The LogDispatcher class represents the object that is responsible for
Expand Down Expand Up @@ -424,8 +424,10 @@ inline bool LogDispatcher::CheckEnabled()
// when the enabler check is tested here. Worst case, the log
// will be printed just a moment after it was turned off.
const LogConfig* config = src_config; // to enforce using const operator[]
config->lock();
int configured_enabled_fa = config->enabled_fa[fa];
int configured_maxlevel = config->max_level;
config->unlock();

return configured_enabled_fa && level <= configured_maxlevel;
}
Expand Down

0 comments on commit f7b32e7

Please sign in to comment.