You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mg...@apache.org on 2021/10/14 17:39:18 UTC
[qpid-dispatch] branch main updated: DISPATCH-1956: log.c rewrite
to reduce locking scope This closes #1376
This is an automated email from the ASF dual-hosted git repository.
mgoulish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/main by this push:
new 9416478 DISPATCH-1956: log.c rewrite to reduce locking scope This closes #1376
9416478 is described below
commit 94164788cebf38d28b4213f5977cac1d62933ad4
Author: mgoulish <mg...@redhat.com>
AuthorDate: Thu Oct 14 11:26:24 2021 -0400
DISPATCH-1956: log.c rewrite to reduce locking scope
This closes #1376
---
include/qpid/dispatch/log.h | 17 +++++++++--------
src/log.c | 31 +++++++++++++++++--------------
2 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/include/qpid/dispatch/log.h b/include/qpid/dispatch/log.h
index 6265029..5a65f68 100644
--- a/include/qpid/dispatch/log.h
+++ b/include/qpid/dispatch/log.h
@@ -27,14 +27,15 @@
/** Logging levels */
typedef enum {
- QD_LOG_NONE =0x00, ///< No logging
- QD_LOG_TRACE =0x01, ///< High volume messages, o(n) or more for n message transfers.
- QD_LOG_DEBUG =0x02, ///< Debugging messages useful to developers.
- QD_LOG_INFO =0x04, ///< Information messages useful to users
- QD_LOG_NOTICE =0x08, ///< Notice of important but non-error events.
- QD_LOG_WARNING =0x10, ///< Warning of event that may be a problem.
- QD_LOG_ERROR =0x20, ///< Error, definitely a problem
- QD_LOG_CRITICAL =0x40, ///< Critical error, data loss or process shut-down.
+ QD_LOG_NONE =0x00, ///< No logging
+ QD_LOG_TRACE =0x01, ///< High volume messages, o(n) or more for n message transfers.
+ QD_LOG_DEBUG =0x02, ///< Debugging messages useful to developers.
+ QD_LOG_INFO =0x04, ///< Information messages useful to users
+ QD_LOG_NOTICE =0x08, ///< Notice of important but non-error events.
+ QD_LOG_WARNING =0x10, ///< Warning of event that may be a problem.
+ QD_LOG_ERROR =0x20, ///< Error, definitely a problem
+ QD_LOG_CRITICAL =0x40, ///< Critical error, data loss or process shut-down.
+ QD_LOG_UNDEFINED =0x7FFFFFFF, ///< No log level defined, so none will be masked out.
} qd_log_level_t;
typedef struct qd_log_source_t qd_log_source_t;
diff --git a/src/log.c b/src/log.c
index 5599483..3262bdb 100644
--- a/src/log.c
+++ b/src/log.c
@@ -43,6 +43,7 @@
#define LOG_MAX (QD_LOG_TEXT_MAX+128)
#define LIST_MAX 1000
+
// log.c lock strategy ========================================
//
// log sources ----------------------
@@ -214,7 +215,7 @@ typedef enum {DEFAULT, NONE, TRACE, DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICA
struct qd_log_source_t {
DEQ_LINKS(qd_log_source_t);
char *module;
- int mask;
+ sys_atomic_t mask;
int includeTimestamp; /* boolean or -1 means not set */
int includeSource; /* boolean or -1 means not set */
bool syslog;
@@ -237,7 +238,7 @@ typedef struct level_t {
#define LEVEL(name, QD_LOG, SYSLOG) { name, QD_LOG, ALL_BITS & ~(QD_LOG-1), SYSLOG }
static level_t levels[] = {
- {"default", -1, -1, 0},
+ {"default", QD_LOG_UNDEFINED, QD_LOG_UNDEFINED, 0},
{"none", 0, 0, 0},
LEVEL("trace", QD_LOG_TRACE, LOG_DEBUG), /* syslog has no trace level */
LEVEL("debug", QD_LOG_DEBUG, LOG_DEBUG),
@@ -273,7 +274,7 @@ static const level_t *level_for_name(const char *name, int len) {
}
/*
- Return -1 and set qd_error if not a valid bit.
+ Return undefined and set qd_error if not a valid bit.
Translate so that the min valid level index is 0.
*/
static int level_index_for_bit(int bit) {
@@ -285,7 +286,7 @@ static int level_index_for_bit(int bit) {
}
qd_error(QD_ERROR_CONFIG, "'%d' is not a valid log level bit.", bit);
- return -1;
+ return QD_LOG_UNDEFINED;
}
/// Return the name of log level or 0 if not found.
@@ -383,7 +384,7 @@ static void write_log(qd_log_source_t *log_source, qd_log_entry_t *entry)
/// Reset the log source to the default state
static void qd_log_source_defaults(qd_log_source_t *src) {
- src->mask = -1;
+ sys_atomic_set(&src->mask, (uint32_t) QD_LOG_UNDEFINED);
src->includeTimestamp = -1;
src->includeSource = -1;
log_sink_decref(src->sink);
@@ -419,8 +420,11 @@ static void qd_log_source_free(qd_log_source_t *src) {
bool qd_log_enabled(qd_log_source_t *source, qd_log_level_t level) {
if (!source) return false;
- int mask = source->mask == -1 ? default_log_source->mask : source->mask;
- return level & mask;
+ uint32_t mask = sys_atomic_get(&source->mask);
+ if (mask == QD_LOG_UNDEFINED) {
+ mask = sys_atomic_get(&default_log_source->mask);
+ }
+ return !!(level & mask);
}
void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, bool check_level, const char *file, int line, const char *fmt, va_list ap)
@@ -430,7 +434,7 @@ void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, bool check_leve
// We can always decide not to look at it later,
// based on its used/unused status.
int level_index = level_index_for_bit(level);
- if (level_index < 0)
+ if (level_index == QD_LOG_UNDEFINED)
qd_error_clear();
else {
sys_mutex_lock(source->lock);
@@ -517,6 +521,7 @@ static void _add_log_source (const char *module_name) {
qd_log_source_t *log_source;
log_source = NEW(qd_log_source_t);
ZERO(log_source);
+ sys_atomic_init(&log_source->mask , QD_LOG_UNDEFINED);
log_source->module = qd_strdup(module_name);
qd_log_source_defaults(log_source);
log_source->lock = sys_mutex();
@@ -555,7 +560,7 @@ void qd_log_initialize(void)
entries_lock = sys_mutex();
- default_log_source->mask = levels[INFO].mask;
+ sys_atomic_set(&default_log_source->mask, QD_LOG_UNDEFINED);
default_log_source->includeTimestamp = true;
default_log_source->includeSource = 0;
default_log_source->sink = log_sink(SINK_STDERR);
@@ -637,8 +642,7 @@ qd_error_t qd_log_entity(qd_entity_t *entity)
QD_ERROR_BREAK();
}
- qd_log_source_t *log_source = qd_log_source(module); /* The original(already existing) log source */
-
+ qd_log_source_t *log_source = qd_log_source(module);
sys_mutex_lock(log_source->lock);
if (has_output_file) {
@@ -671,7 +675,7 @@ qd_error_t qd_log_entity(qd_entity_t *entity)
break;
}
else {
- log_source->mask = mask;
+ sys_atomic_set(&log_source->mask, mask);
}
if (qd_log_enabled(log_source, QD_LOG_TRACE)) {
@@ -688,8 +692,7 @@ qd_error_t qd_log_entity(qd_entity_t *entity)
log_source->includeSource = include_source;
}
- sys_mutex_unlock(log_source->lock);
-
+ sys_mutex_unlock(log_source->lock);
} while(0);
if (error_in_output) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org