Skip to content

Commit

Permalink
Fix zlog_env_conf concurrency question (HardySimpson#269)
Browse files Browse the repository at this point in the history
* Fix zlog_env_conf concurrency question
  • Loading branch information
breadmechanic authored Sep 7, 2024
1 parent d0b6673 commit f7e92a4
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/zlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,9 @@ void vzlog(zlog_category_t * category,
* For speed up, if one log will not be output,
* There is no need to aquire rdlock.
*/
if (zlog_category_needless_level(category, level)) return;

pthread_rwlock_rdlock(&zlog_env_lock);

if (zlog_category_needless_level(category, level)) goto exit;

if (!zlog_env_is_init) {
zc_error("never call zlog_init() or dzlog_init() before");
Expand Down Expand Up @@ -856,9 +856,9 @@ void hzlog(zlog_category_t *category,
{
zlog_thread_t *a_thread;

if (zlog_category_needless_level(category, level)) return;

pthread_rwlock_rdlock(&zlog_env_lock);

if (zlog_category_needless_level(category, level)) goto exit;

if (!zlog_env_is_init) {
zc_error("never call zlog_init() or dzlog_init() before");
Expand Down Expand Up @@ -904,9 +904,9 @@ void vdzlog(const char *file, size_t filelen,
{
zlog_thread_t *a_thread;

if (zlog_category_needless_level(zlog_default_category, level)) return;

pthread_rwlock_rdlock(&zlog_env_lock);

if (zlog_category_needless_level(zlog_default_category, level)) goto exit;

if (!zlog_env_is_init) {
zc_error("never call zlog_init() or dzlog_init() before");
Expand Down Expand Up @@ -957,9 +957,9 @@ void hdzlog(const char *file, size_t filelen,
{
zlog_thread_t *a_thread;

if (zlog_category_needless_level(zlog_default_category, level)) return;

pthread_rwlock_rdlock(&zlog_env_lock);

if (zlog_category_needless_level(zlog_default_category, level)) goto exit;

if (!zlog_env_is_init) {
zc_error("never call zlog_init() or dzlog_init() before");
Expand Down Expand Up @@ -1012,9 +1012,9 @@ void zlog(zlog_category_t * category,
zlog_thread_t *a_thread;
va_list args;

if (category && zlog_category_needless_level(category, level)) return;

pthread_rwlock_rdlock(&zlog_env_lock);

if (category && zlog_category_needless_level(category, level)) goto exit;

if (!zlog_env_is_init) {
zc_error("never call zlog_init() or dzlog_init() before");
Expand Down Expand Up @@ -1188,7 +1188,13 @@ int zlog_set_record(const char *rname, zlog_record_fn record_output)
/*******************************************************************************/
int zlog_level_enabled(zlog_category_t *category, const int level)
{
return category && ((zlog_category_needless_level(category, level) == 0));
int enable = 0;

pthread_rwlock_rdlock(&zlog_env_lock);
enable = category && ((zlog_category_needless_level(category, level) == 0));
pthread_rwlock_unlock(&zlog_env_lock);

return enable;
}

const char *zlog_version(void) { return ZLOG_VERSION; }

0 comments on commit f7e92a4

Please sign in to comment.