prefix global variables with g_
This commit is contained in:
+31
-31
@@ -43,11 +43,11 @@ struct uc_log_args {
|
|||||||
|
|
||||||
//Global lock for the logging system, as logging could be performed from any thread. All operations must grab
|
//Global lock for the logging system, as logging could be performed from any thread. All operations must grab
|
||||||
//this lock before accessing any the global data.
|
//this lock before accessing any the global data.
|
||||||
static pthread_mutex_t log_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t g_log_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static struct uc_log_modules modules;
|
static struct uc_log_modules g_modules;
|
||||||
|
|
||||||
static const struct uc_log_module unknown_module = {
|
static const struct uc_log_module g_unknown_module = {
|
||||||
.id = -1,
|
.id = -1,
|
||||||
.short_name = "UNKNOWN",
|
.short_name = "UNKNOWN",
|
||||||
.long_name = "Unknown log module",
|
.long_name = "Unknown log module",
|
||||||
@@ -55,9 +55,9 @@ static const struct uc_log_module unknown_module = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//All destinations. The log_lock must be held while accessing
|
//All destinations. The g_log_lock must be held while accessing
|
||||||
//this list an anything contained within it.
|
//this list an anything contained within it.
|
||||||
static SLIST_HEAD(, uc_log_destination) destinations;
|
static SLIST_HEAD(, uc_log_destination) g_destinations;
|
||||||
static int uc_log_reopen_file(struct uc_log_destination *dest);
|
static int uc_log_reopen_file(struct uc_log_destination *dest);
|
||||||
|
|
||||||
inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l)
|
inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l)
|
||||||
@@ -174,35 +174,35 @@ void uc_log_add_destination(struct uc_log_destination *dest)
|
|||||||
if (dest == NULL)
|
if (dest == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pthread_mutex_lock(&log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
//make sure the destination isn't added twice.
|
//make sure the destination isn't added twice.
|
||||||
SLIST_FOREACH(it, &destinations, entry) {
|
SLIST_FOREACH(it, &g_destinations, entry) {
|
||||||
if (dest == it)
|
if (dest == it)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add if it isn't already in the list
|
//add if it isn't already in the list
|
||||||
if (it == NULL) {
|
if (it == NULL) {
|
||||||
SLIST_INSERT_HEAD(&destinations, dest, entry);
|
SLIST_INSERT_HEAD(&g_destinations, dest, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&log_lock);
|
pthread_mutex_unlock(&g_log_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
//hold log_lock while calling this.
|
//hold g_log_lock while calling this.
|
||||||
static inline void uc_log_remove_dest_unlocked(struct uc_log_destination *dest)
|
static inline void uc_log_remove_dest_unlocked(struct uc_log_destination *dest)
|
||||||
{
|
{
|
||||||
struct uc_log_destination *it;
|
struct uc_log_destination *it;
|
||||||
|
|
||||||
//check that it's not already removed
|
//check that it's not already removed
|
||||||
SLIST_FOREACH(it, &destinations, entry) {
|
SLIST_FOREACH(it, &g_destinations, entry) {
|
||||||
if (it == dest)
|
if (it == dest)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it != NULL) {
|
if (it != NULL) {
|
||||||
SLIST_REMOVE(&destinations, dest, uc_log_destination, entry);
|
SLIST_REMOVE(&g_destinations, dest, uc_log_destination, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,11 +211,11 @@ void uc_log_remove_destination(struct uc_log_destination *dest)
|
|||||||
if (dest == NULL)
|
if (dest == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pthread_mutex_lock(&log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
uc_log_remove_dest_unlocked(dest);
|
uc_log_remove_dest_unlocked(dest);
|
||||||
|
|
||||||
pthread_mutex_unlock(&log_lock);
|
pthread_mutex_unlock(&g_log_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uc_log_delete_destination(struct uc_log_destination *dest)
|
void uc_log_delete_destination(struct uc_log_destination *dest)
|
||||||
@@ -223,7 +223,7 @@ void uc_log_delete_destination(struct uc_log_destination *dest)
|
|||||||
if (dest == NULL)
|
if (dest == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pthread_mutex_lock(&log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
//remove it, it's ok if the destination is already removed
|
//remove it, it's ok if the destination is already removed
|
||||||
uc_log_remove_dest_unlocked(dest);
|
uc_log_remove_dest_unlocked(dest);
|
||||||
@@ -248,7 +248,7 @@ void uc_log_delete_destination(struct uc_log_destination *dest)
|
|||||||
|
|
||||||
free(dest);
|
free(dest);
|
||||||
|
|
||||||
pthread_mutex_unlock(&log_lock);
|
pthread_mutex_unlock(&g_log_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uc_log_reopen_file(struct uc_log_destination *dest)
|
static int uc_log_reopen_file(struct uc_log_destination *dest)
|
||||||
@@ -275,23 +275,23 @@ int uc_log_reopen_files(void)
|
|||||||
struct uc_log_destination *dest;
|
struct uc_log_destination *dest;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
SLIST_FOREACH(dest, &destinations, entry) {
|
SLIST_FOREACH(dest, &g_destinations, entry) {
|
||||||
|
|
||||||
if (dest->dest_type == UC_LDEST_FILE) {
|
if (dest->dest_type == UC_LDEST_FILE) {
|
||||||
rc = uc_log_reopen_file(dest);
|
rc = uc_log_reopen_file(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&log_lock);
|
pthread_mutex_unlock(&g_log_lock);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uc_log_init(struct uc_log_modules *user_modules)
|
void uc_log_init(struct uc_log_modules *user_modules)
|
||||||
{
|
{
|
||||||
modules = *user_modules;
|
g_modules = *user_modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level)
|
int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level)
|
||||||
@@ -299,17 +299,17 @@ int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level)
|
|||||||
int rc = -1;
|
int rc = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pthread_mutex_lock(&log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
for (i = 0; i < modules.cnt; i++) {
|
for (i = 0; i < g_modules.cnt; i++) {
|
||||||
if (modules.mods[i].id == module) {
|
if (g_modules.mods[i].id == module) {
|
||||||
modules.mods[i].log_level = level;
|
g_modules.mods[i].log_level = level;
|
||||||
rc = 0;
|
rc = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&log_lock);
|
pthread_mutex_unlock(&g_log_lock);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -402,22 +402,22 @@ void uc_logf(int log_level, int module, int raw,
|
|||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
pthread_mutex_lock(&log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
//Find the module doign the logging, or use the unknown module -
|
//Find the module doign the logging, or use the unknown module -
|
||||||
//the latter would indicate a bug somewhere in the application as it should
|
//the latter would indicate a bug somewhere in the application as it should
|
||||||
//always specify a known module
|
//always specify a known module
|
||||||
if (module >= 0 && module < modules.cnt)
|
if (module >= 0 && module < g_modules.cnt)
|
||||||
log_module = &modules.mods[module];
|
log_module = &g_modules.mods[module];
|
||||||
else
|
else
|
||||||
log_module = &unknown_module;
|
log_module = &g_unknown_module;
|
||||||
|
|
||||||
//Check if the module should not be logged
|
//Check if the module should not be logged
|
||||||
if (log_level < log_module->log_level)
|
if (log_level < log_module->log_level)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
//do logging for each destination
|
//do logging for each destination
|
||||||
SLIST_FOREACH(dest, &destinations, entry) {
|
SLIST_FOREACH(dest, &g_destinations, entry) {
|
||||||
va_list apc;
|
va_list apc;
|
||||||
|
|
||||||
if (log_level >= dest->log_level) {
|
if (log_level >= dest->log_level) {
|
||||||
@@ -449,7 +449,7 @@ void uc_logf(int log_level, int module, int raw,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
pthread_mutex_unlock(&log_lock);
|
pthread_mutex_unlock(&g_log_lock);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user