]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
capmt: more atomic changes (clang sanitizer)
authorJaroslav Kysela <perex@perex.cz>
Tue, 30 Jan 2018 17:50:39 +0000 (18:50 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 30 Jan 2018 17:55:43 +0000 (18:55 +0100)
src/descrambler/caclient.c
src/descrambler/capmt.c

index 58462b7bc626c83ba4efac87707ae6e38ecef815..7a8f08de44de59bbcb950b72de2c52c8ae843b95 100644 (file)
@@ -380,10 +380,8 @@ caclient_caid_update
 void
 caclient_set_status(caclient_t *cac, caclient_status_t status)
 {
-  if (cac->cac_status != status) {
-    cac->cac_status = status;
+  if (atomic_exchange(&cac->cac_status, status) != status)
     idnode_lnotify_changed(&cac->cac_id);
-  }
 }
 
 const char *
index a20ce765b2660307095fffaafceca66b4b7a6840..0ccaaf5a4f20d4c1e76c3e4153c9553f8cf84909 100644 (file)
@@ -947,11 +947,10 @@ capmt_set_filter(capmt_t *capmt, int adapter, sbuf_t *sb, int offset)
       filter_index >= MAX_FILTER ||
       pid > 8191)
     return;
+  pthread_mutex_lock(&capmt->capmt_mutex);
   cf = &capmt->capmt_demuxes.filters[demux_index];
   if (cf->max && cf->adapter != adapter)
-    return;
-
-  pthread_mutex_lock(&capmt->capmt_mutex);
+    goto end;
 
   /* ECM messages have the higher priority */
   t = NULL;
@@ -1010,6 +1009,7 @@ cont:
     capmt->capmt_demuxes.max = demux_index + 1;
   if (cf->max <= filter_index)
     cf->max = filter_index + 1;
+end:
   pthread_mutex_unlock(&capmt->capmt_mutex);
 }
 
@@ -1817,6 +1817,7 @@ capmt_thread(void *aux)
 
   while (atomic_get(&capmt->capmt_running)) {
     fatal = 0;
+    pthread_mutex_lock(&capmt->capmt_mutex);
     for (i = 0; i < MAX_CA; i++) {
       ca = &capmt->capmt_adapters[i];
       ca->ca_number = i;
@@ -1835,6 +1836,7 @@ capmt_thread(void *aux)
       capmt->capmt_sock_reconnect[i] = 0;
     }
     capmt_init_demuxes(capmt);
+    pthread_mutex_unlock(&capmt->capmt_mutex);
 
     /* Accessible */
     if (capmt->capmt_sockfile && capmt->capmt_oscam != CAPMT_OSCAM_TCP &&