prefix global variables with g_

This commit is contained in:
Nils O. Selåsdal
2013-03-07 21:11:16 +01:00
parent 5e376d47fc
commit b80c2f633f
+31 -31
View File
@@ -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
//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,
.short_name = "UNKNOWN",
.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.
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);
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)
return;
pthread_mutex_lock(&log_lock);
pthread_mutex_lock(&g_log_lock);
//make sure the destination isn't added twice.
SLIST_FOREACH(it, &destinations, entry) {
SLIST_FOREACH(it, &g_destinations, entry) {
if (dest == it)
break;
}
//add if it isn't already in the list
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)
{
struct uc_log_destination *it;
//check that it's not already removed
SLIST_FOREACH(it, &destinations, entry) {
SLIST_FOREACH(it, &g_destinations, entry) {
if (it == dest)
break;
}
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)
return;
pthread_mutex_lock(&log_lock);
pthread_mutex_lock(&g_log_lock);
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)
@@ -223,7 +223,7 @@ void uc_log_delete_destination(struct uc_log_destination *dest)
if (dest == NULL)
return;
pthread_mutex_lock(&log_lock);
pthread_mutex_lock(&g_log_lock);
//remove it, it's ok if the destination is already removed
uc_log_remove_dest_unlocked(dest);
@@ -248,7 +248,7 @@ void uc_log_delete_destination(struct uc_log_destination *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)
@@ -275,23 +275,23 @@ int uc_log_reopen_files(void)
struct uc_log_destination *dest;
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) {
rc = uc_log_reopen_file(dest);
}
}
pthread_mutex_unlock(&log_lock);
pthread_mutex_unlock(&g_log_lock);
return rc;
}
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)
@@ -299,17 +299,17 @@ int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level)
int rc = -1;
int i;
pthread_mutex_lock(&log_lock);
pthread_mutex_lock(&g_log_lock);
for (i = 0; i < modules.cnt; i++) {
if (modules.mods[i].id == module) {
modules.mods[i].log_level = level;
for (i = 0; i < g_modules.cnt; i++) {
if (g_modules.mods[i].id == module) {
g_modules.mods[i].log_level = level;
rc = 0;
break;
}
}
pthread_mutex_unlock(&log_lock);
pthread_mutex_unlock(&g_log_lock);
return rc;
}
@@ -402,22 +402,22 @@ void uc_logf(int log_level, int module, int raw,
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 -
//the latter would indicate a bug somewhere in the application as it should
//always specify a known module
if (module >= 0 && module < modules.cnt)
log_module = &modules.mods[module];
if (module >= 0 && module < g_modules.cnt)
log_module = &g_modules.mods[module];
else
log_module = &unknown_module;
log_module = &g_unknown_module;
//Check if the module should not be logged
if (log_level < log_module->log_level)
goto out;
//do logging for each destination
SLIST_FOREACH(dest, &destinations, entry) {
SLIST_FOREACH(dest, &g_destinations, entry) {
va_list apc;
if (log_level >= dest->log_level) {
@@ -449,7 +449,7 @@ void uc_logf(int log_level, int module, int raw,
}
out:
pthread_mutex_unlock(&log_lock);
pthread_mutex_unlock(&g_log_lock);
va_end(ap);
}