]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
uuid: add uuid_set_copy(), fix one problem reported by cclang sanitizer
authorJaroslav Kysela <perex@perex.cz>
Wed, 17 Jan 2018 17:21:15 +0000 (18:21 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 17 Jan 2018 17:34:21 +0000 (18:34 +0100)
src/idnode.c
src/uuid.c
src/uuid.h

index 7663c5d2f7162e6b766bacb6888d75e2e751fc8b..e84718c24ef595f01a8c0cf1d9bd8d2976654e46 100644 (file)
@@ -1940,6 +1940,7 @@ save_thread ( void *aux )
   tvh_uuid_t *uuid;
   char filename[PATH_MAX];
   tvh_uuid_set_t set, tset;
+  int lnotify;
 
   uuid_set_init(&set, 10);
   uuid_set_init(&tset, 10);
@@ -1949,10 +1950,14 @@ save_thread ( void *aux )
   pthread_mutex_lock(&global_lock);
 
   while (atomic_get(&save_running)) {
-    if (((ise = TAILQ_FIRST(&idnodes_save)) == NULL ||
-         (ise->ise_reqtime + IDNODE_SAVE_DELAY > mclk())) &&
-         uuid_set_empty(&idnode_lnotify_set) &&
-         uuid_set_empty(&idnode_lnotify_title_set)) {
+    if ((ise = TAILQ_FIRST(&idnodes_save)) == NULL ||
+        ise->ise_reqtime + IDNODE_SAVE_DELAY > mclk()) {
+      pthread_mutex_lock(&idnode_lnotify_mutex);
+      lnotify = !uuid_set_empty(&idnode_lnotify_set) ||
+                !uuid_set_empty(&idnode_lnotify_title_set);
+      pthread_mutex_unlock(&idnode_lnotify_mutex);
+      if (lnotify)
+        goto lnotifygo;
       if (ise)
         mtimer_arm_abs(&save_timer, idnode_save_trigger_thread_cb, NULL,
                        ise->ise_reqtime + IDNODE_SAVE_DELAY);
@@ -1971,6 +1976,7 @@ save_thread ( void *aux )
       }
       pthread_mutex_lock(&global_lock);
     }
+lnotifygo:
     pthread_mutex_lock(&idnode_lnotify_mutex);
     if (!uuid_set_empty(&idnode_lnotify_set)) {
       set = idnode_lnotify_set;
index 75a88773d8df59a1225a9d11fd623e6e5ba406fd..2443e9205053afe3c3885d0803525d9f1d12fc49 100644 (file)
@@ -166,6 +166,23 @@ uuid_set_init( tvh_uuid_set_t *us, uint32_t alloc_chunk )
   us->us_alloc_chunk = alloc_chunk ?: 10;
 }
 
+/* Copy uuid set */
+tvh_uuid_set_t *
+uuid_set_copy( tvh_uuid_set_t *dst, const tvh_uuid_set_t *src )
+{
+  size_t size;
+  memset(&dst, 0, sizeof(*dst));
+  dst->us_alloc_chunk = src->us_alloc_chunk;
+  size = sizeof(tvh_uuid_t) * src->us_size;
+  dst->us_array = malloc(size);
+  if (dst->us_array == NULL)
+    return NULL;
+  memcpy(dst->us_array, src->us_array, size);
+  dst->us_size = src->us_size;
+  dst->us_count = src->us_count;
+  return dst;
+}
+
 /* Add an uuid to set */
 tvh_uuid_t *
 uuid_set_add ( tvh_uuid_set_t *us, const tvh_uuid_t *u ) 
index d441a28e4370e92370f04ba8c338bf2ad0497d9a..ebadbb20c0c1ad290d877c73bb0b93df9f9585bf 100644 (file)
@@ -87,6 +87,11 @@ int uuid_hexvalid ( const char *uuid );
  */
 void uuid_set_init( tvh_uuid_set_t *us, uint32_t alloc_chunk );
 
+/**
+ *
+ */
+tvh_uuid_set_t *uuid_set_copy( tvh_uuid_set_t *dst, const tvh_uuid_set_t *src );
+
 /**
  *
  */