Slight refactor of checking if a destination exists
This commit is contained in:
+18
-18
@@ -239,24 +239,30 @@ struct UCLogDestination *uc_log_new_file(const char *filename, int log_level, in
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uc_log_add_destination(struct UCLogDestination *dest)
|
//Check if a destination already exists (hold g_log_lock when calling this)
|
||||||
|
static int uc_log_dest_exists_unlocked(struct UCLogDestination *dest)
|
||||||
{
|
{
|
||||||
struct UCLogDestination *it;
|
struct UCLogDestination *it;
|
||||||
int exists = 0;
|
|
||||||
|
UC_TAILQ_FOREACH_CONTAINER(it, entry, &g_destinations) {
|
||||||
|
if (dest == it) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uc_log_add_destination(struct UCLogDestination *dest)
|
||||||
|
{
|
||||||
|
int exists;
|
||||||
|
|
||||||
if (dest == NULL)
|
if (dest == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_log_lock);
|
pthread_mutex_lock(&g_log_lock);
|
||||||
|
|
||||||
//make sure the destination isn't added twice.
|
exists = uc_log_dest_exists_unlocked(dest);
|
||||||
UC_TAILQ_FOREACH_CONTAINER(it, entry, &g_destinations) {
|
|
||||||
if (dest == it) {
|
|
||||||
exists = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//add if it isn't already in the list
|
//add if it isn't already in the list
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
uc_tailq_insert_head(&g_destinations, &dest->entry);
|
uc_tailq_insert_head(&g_destinations, &dest->entry);
|
||||||
@@ -268,16 +274,10 @@ void uc_log_add_destination(struct UCLogDestination *dest)
|
|||||||
//hold g_log_lock while calling this.
|
//hold g_log_lock while calling this.
|
||||||
static inline void uc_log_remove_dest_unlocked(struct UCLogDestination *dest)
|
static inline void uc_log_remove_dest_unlocked(struct UCLogDestination *dest)
|
||||||
{
|
{
|
||||||
struct UCLogDestination *it;
|
int exists;
|
||||||
int exists = 0;
|
|
||||||
|
|
||||||
//check that it's not already removed
|
//check that it's not already removed
|
||||||
UC_TAILQ_FOREACH_CONTAINER(it, entry, &g_destinations) {
|
exists = uc_log_dest_exists_unlocked(dest);
|
||||||
if (it == dest) {
|
|
||||||
exists = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
uc_tailq_remove(&dest->entry);
|
uc_tailq_remove(&dest->entry);
|
||||||
|
|||||||
Reference in New Issue
Block a user