From: Jaroslav Kysela Date: Tue, 8 Mar 2016 12:31:05 +0000 (+0100) Subject: tasklet: improve the callback call sequence X-Git-Tag: v4.2.1~939 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=149d5b37a8ef6007bccc0d2877e5ac493b4ec4d2;p=thirdparty%2Ftvheadend.git tasklet: improve the callback call sequence --- diff --git a/src/main.c b/src/main.c index 2630e61fa..75c5add40 100644 --- a/src/main.c +++ b/src/main.c @@ -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);