From: Ondřej Surý Date: Fri, 12 Jul 2019 14:44:51 +0000 (+0200) Subject: Properly initialize atomic variables X-Git-Tag: v9.15.6~75^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07879f354c9778cf305ec477de3c78d1d151c8d4;p=thirdparty%2Fbind9.git Properly initialize atomic variables --- diff --git a/lib/isc/tests/task_test.c b/lib/isc/tests/task_test.c index a7c22fc16b8..282dab035b5 100644 --- a/lib/isc/tests/task_test.c +++ b/lib/isc/tests/task_test.c @@ -46,9 +46,9 @@ static bool verbose = false; static isc_mutex_t lock; static isc_condition_t cv; -atomic_int counter = 0; +atomic_int_fast32_t counter; static int active[10]; -static atomic_bool done = false; +static atomic_bool done; static int _setup(void **state) { @@ -112,7 +112,7 @@ _teardown(void **state) { static void set(isc_task_t *task, isc_event_t *event) { - atomic_int *value = (atomic_int *) event->ev_arg; + atomic_int_fast32_t *value = (atomic_int_fast32_t *) event->ev_arg; UNUSED(task); @@ -122,7 +122,7 @@ set(isc_task_t *task, isc_event_t *event) { static void set_and_drop(isc_task_t *task, isc_event_t *event) { - atomic_int *value = (atomic_int *) event->ev_arg; + atomic_int_fast32_t *value = (atomic_int_fast32_t *) event->ev_arg; UNUSED(task); @@ -154,12 +154,14 @@ all_events(void **state) { isc_result_t result; isc_task_t *task = NULL; isc_event_t *event = NULL; - atomic_int a = 0, b = 0; + atomic_int_fast32_t a, b; int i = 0; UNUSED(state); atomic_init(&counter, 1); + atomic_init(&a, 0); + atomic_init(&b, 0); result = isc_task_create(taskmgr, 0, &task); assert_int_equal(result, ISC_R_SUCCESS); @@ -196,12 +198,17 @@ privileged_events(void **state) { isc_result_t result; isc_task_t *task1 = NULL, *task2 = NULL; isc_event_t *event = NULL; - atomic_int a = 0, b = 0, c = 0, d = 0, e = 0; + atomic_int_fast32_t a, b, c, d, e; int i = 0; UNUSED(state); atomic_init(&counter, 1); + atomic_init(&a, 0); + atomic_init(&b, 0); + atomic_init(&c, 0); + atomic_init(&d, 0); + atomic_init(&e, 0); /* * Pause the task manager so we can fill up the work queue @@ -312,12 +319,17 @@ privilege_drop(void **state) { isc_result_t result; isc_task_t *task1 = NULL, *task2 = NULL; isc_event_t *event = NULL; - atomic_int a = -1, b = -1, c = -1, d = -1, e = -1; /* non valid states */ + atomic_int_fast32_t a, b, c, d, e; /* non valid states */ int i = 0; UNUSED(state); atomic_init(&counter, 1); + atomic_init(&a, -1); + atomic_init(&b, -1); + atomic_init(&c, -1); + atomic_init(&d, -1); + atomic_init(&e, -1); /* * Pause the task manager so we can fill up the work queue @@ -752,7 +764,7 @@ manytasks(void **state) { static int nevents = 0; static int nsdevents = 0; static int senders[4]; -atomic_bool ready = ATOMIC_VAR_INIT(false), all_done = ATOMIC_VAR_INIT(false); +atomic_bool ready, all_done; static void sd_sde1(isc_task_t *task, isc_event_t *event) { @@ -791,7 +803,7 @@ sd_event1(isc_task_t *task, isc_event_t *event) { UNUSED(task); LOCK(&lock); - while (!ready) { + while (!atomic_load(&ready)) { WAIT(&cv, &lock); } UNLOCK(&lock); @@ -828,7 +840,8 @@ shutdown(void **state) { nevents = nsdevents = 0; event_type = 3; - ready = false; + atomic_init(&ready, false); + atomic_init(&all_done, false); LOCK(&lock); @@ -868,7 +881,7 @@ shutdown(void **state) { /* * Now we free the task by signaling cv. */ - ready = true; + atomic_store(&ready, true); SIGNAL(&cv); UNLOCK(&lock); @@ -966,7 +979,7 @@ static isc_eventtype_t purge_type_last; static void *purge_tag; static int eventcnt; -atomic_bool started = false; +atomic_bool started; static void pg_event1(isc_task_t *task, isc_event_t *event) {