]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tasklet: improve the callback call sequence
authorJaroslav Kysela <perex@perex.cz>
Tue, 8 Mar 2016 12:31:05 +0000 (13:31 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 8 Mar 2016 12:31:05 +0000 (13:31 +0100)
src/main.c

index 2630e61fa223b74d8d9936911ff8427f26fabb99..75c5add4002e94cca78d514476823bee00ce3e7f 100644 (file)
@@ -436,6 +436,8 @@ static void *
 tasklet_thread ( void *aux )
 {
   tasklet_t *tsk;
+  tsk_callback_t *tsk_cb;
+  void *opaque;
 
   tvhtread_renice(20);
 
@@ -446,13 +448,16 @@ tasklet_thread ( void *aux )
       tvh_cond_wait(&tasklet_cond, &tasklet_lock);
       continue;
     }
-    if (tsk->tsk_callback) {
-      tsk->tsk_callback(tsk->tsk_opaque, 0);
-      tsk->tsk_callback = NULL;
-    }
+    /* the callback might re-initiaze tasklet, save everythin */
     TAILQ_REMOVE(&tasklets, tsk, tsk_link);
+    tsk_cb = tsk->tsk_callback;
+    opaque = tsk->tsk_opaque;
+    tsk->tsk_callback = NULL;
     if (tsk->tsk_allocated)
       free(tsk);
+    /* now, the callback can be safely called */
+    if (tsk_cb)
+      tsk_cb(opaque, 0);
   }
   pthread_mutex_unlock(&tasklet_lock);