Browse Source

Add atomicity qualifier

dynamic-accesslists
Dirk Engling 2 years ago
parent
commit
6e591d7437
  1. 18
      ot_accesslist.c

18
ot_accesslist.c

@ -54,10 +54,10 @@ struct ot_accesslist {
ot_time base; ot_time base;
ot_accesslist *next; ot_accesslist *next;
}; };
static ot_accesslist * g_accesslist = NULL; static ot_accesslist * _Atomic g_accesslist = NULL;
#ifdef WANT_DYNAMIC_ACCESSLIST #ifdef WANT_DYNAMIC_ACCESSLIST
static ot_accesslist * g_accesslist_add = NULL; static ot_accesslist * _Atomic g_accesslist_add = NULL;
static ot_accesslist * g_accesslist_delete = NULL; static ot_accesslist * _Atomic g_accesslist_delete = NULL;
#endif #endif
/* Helpers to work on access lists */ /* Helpers to work on access lists */
@ -232,7 +232,7 @@ static void * accesslist_worker( void * args ) {
#ifdef WANT_DYNAMIC_ACCESSLIST #ifdef WANT_DYNAMIC_ACCESSLIST
static pthread_t thread_adder_id, thread_deleter_id; static pthread_t thread_adder_id, thread_deleter_id;
static void * accesslist_adddel_worker(char * fifoname, ot_accesslist ** adding_to, ot_accesslist ** removing_from) { static void * accesslist_adddel_worker(char * fifoname, ot_accesslist * _Atomic * adding_to, ot_accesslist * _Atomic * removing_from) {
struct stat st; struct stat st;
if (!stat(fifoname, &st)) { if (!stat(fifoname, &st)) {
@ -297,13 +297,14 @@ printf("parsed info_hash %20s\n", info_hash);
} }
} }
} }
accesslist_clean(*removing_from);
/* Simple case: there's no adding_to list yet, create one with one member */ /* Simple case: there's no adding_to list yet, create one with one member */
if (!*adding_to) { if (!*adding_to) {
*adding_to = accesslist_make(NULL, 1); ot_accesslist * accesslist_new = accesslist_make(NULL, 1);
if (*adding_to) if (accesslist_new) {
memcpy((*adding_to)->list, info_hash, sizeof(ot_hash)); memcpy(accesslist_new->list, info_hash, sizeof(ot_hash));
*adding_to = accesslist_new;
}
} else { } else {
int exactmatch = 0; int exactmatch = 0;
ot_hash * insert_point = binary_search( info_hash, (*adding_to)->list, (*adding_to)->size, OT_HASH_COMPARE_SIZE, sizeof(ot_hash), &exactmatch ); ot_hash * insert_point = binary_search( info_hash, (*adding_to)->list, (*adding_to)->size, OT_HASH_COMPARE_SIZE, sizeof(ot_hash), &exactmatch );
@ -320,7 +321,6 @@ printf("parsed info_hash %20s\n", info_hash);
} }
} }
} }
accesslist_clean(*adding_to);
pthread_mutex_unlock(&g_accesslist_mutex); pthread_mutex_unlock(&g_accesslist_mutex);
} }

Loading…
Cancel
Save