From: Jaroslav Kysela Date: Thu, 10 Mar 2016 09:01:21 +0000 (+0100) Subject: capmt: use atomic ops for running/reconfigure flags (clang sanitizer) X-Git-Tag: v4.2.1~905 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e549e6a0ce1badc0aa887bbab43c1b8bfb44cd22;p=thirdparty%2Ftvheadend.git capmt: use atomic ops for running/reconfigure flags (clang sanitizer) --- diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index 5a7223260..2da49720a 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -481,7 +481,7 @@ capmt_connect(capmt_t *capmt, int i) capmt->capmt_sock[i] = -1; - if (!capmt->capmt_running) + if (!atomic_get(&capmt->capmt_running)) return -1; if (capmt->capmt_oscam == CAPMT_OSCAM_TCP || @@ -1392,7 +1392,7 @@ handle_ca0(capmt_t *capmt) { i = 0; adapter = -1; - while (capmt->capmt_running) { + while (atomic_get(&capmt->capmt_running)) { nfds = tvhpoll_wait(capmt->capmt_poll, ev, MAX_CA + 1, 500); @@ -1409,7 +1409,7 @@ handle_ca0(capmt_t *capmt) { } tvhtrace("capmt", "%s: thread received shutdown", capmt_name(capmt)); - capmt->capmt_running = 0; + atomic_set(&capmt->capmt_running, 0); continue; } @@ -1487,7 +1487,7 @@ handle_single(capmt_t *capmt) capmt_poll_add(capmt, capmt->capmt_pipe.rd, 0); capmt_poll_add(capmt, capmt->capmt_sock[0], 1); - while (capmt->capmt_running) { + while (atomic_get(&capmt->capmt_running)) { nfds = tvhpoll_wait(capmt->capmt_poll, &ev, 1, 500); @@ -1502,7 +1502,7 @@ handle_single(capmt_t *capmt) } tvhtrace("capmt", "%s: thread received shutdown", capmt_name(capmt)); - capmt->capmt_running = 0; + atomic_set(&capmt->capmt_running, 0); continue; } @@ -1573,7 +1573,7 @@ handle_ca0_wrapper(capmt_t *capmt) capmt_notify_server(capmt, NULL, 1); - while (capmt->capmt_running) { + while (atomic_get(&capmt->capmt_running)) { if (capmt->capmt_sock[0] < 0) break; @@ -1645,7 +1645,7 @@ capmt_thread(void *aux) tvhlog(LOG_INFO, "capmt", "%s active", capmt_name(capmt)); - while (capmt->capmt_running) { + while (atomic_get(&capmt->capmt_running)) { fatal = 0; for (i = 0; i < MAX_CA; i++) { ca = &capmt->capmt_adapters[i]; @@ -1675,12 +1675,12 @@ capmt_thread(void *aux) pthread_mutex_lock(&capmt->capmt_mutex); - while(capmt->capmt_running && capmt->cac_enabled == 0) + while(atomic_get(&capmt->capmt_running) && capmt->cac_enabled == 0) tvh_cond_wait(&capmt->capmt_cond, &capmt->capmt_mutex); pthread_mutex_unlock(&capmt->capmt_mutex); - if (!capmt->capmt_running) continue; + if (!atomic_get(&capmt->capmt_running)) continue; /* open connection to camd.socket */ capmt_connect(capmt, 0); @@ -1750,14 +1750,14 @@ capmt_thread(void *aux) close(capmt->capmt_adapters[i].ca_sock); } - if (capmt->capmt_reconfigure) { - capmt->capmt_reconfigure = 0; - capmt->capmt_running = 1; + if (atomic_get(&capmt->capmt_reconfigure)) { + atomic_set(&capmt->capmt_reconfigure, 0); + atomic_set(&capmt->capmt_running, 1); pthread_mutex_unlock(&capmt->capmt_mutex); continue; } - if (!capmt->capmt_running) { + if (!atomic_get(&capmt->capmt_running)) { pthread_mutex_unlock(&capmt->capmt_mutex); continue; } @@ -2238,23 +2238,23 @@ capmt_conf_changed(caclient_t *cac) caclient_set_status(cac, CACLIENT_STATUS_NONE); return; } - if (!capmt->capmt_running) { - capmt->capmt_running = 1; - capmt->capmt_reconfigure = 0; + if (!atomic_get(&capmt->capmt_running)) { + atomic_set(&capmt->capmt_running, 1); + atomic_set(&capmt->capmt_reconfigure, 0); tvhthread_create(&capmt->capmt_tid, NULL, capmt_thread, capmt, "capmt"); return; } pthread_mutex_lock(&capmt->capmt_mutex); - capmt->capmt_reconfigure = 1; + atomic_set(&capmt->capmt_reconfigure, 1); tvh_cond_signal(&capmt->capmt_cond, 0); pthread_mutex_unlock(&capmt->capmt_mutex); tvh_write(capmt->capmt_pipe.wr, "", 1); } else { - if (!capmt->capmt_running) + if (!atomic_get(&capmt->capmt_running)) return; pthread_mutex_lock(&capmt->capmt_mutex); - capmt->capmt_running = 0; - capmt->capmt_reconfigure = 0; + atomic_set(&capmt->capmt_running, 0); + atomic_set(&capmt->capmt_reconfigure, 0); tvh_cond_signal(&capmt->capmt_cond, 0); tid = capmt->capmt_tid; pthread_mutex_unlock(&capmt->capmt_mutex);