From c377febe7ac559a6940143db09a092b511647958 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Sat, 11 May 2013 14:29:29 +0530 Subject: syncop: Update synctask state appropriately * Earlier, SYNCOP macro, the only consumer of synctask_yield, would set the task->state to SYNCTASK_SUSPEND. Today, we have glusterd having its own wrapper macros which don't set task's state. There is also the syncbarrier and synclock framework, which also participate in a synctask's scheduling (and need to keep a task's state up to date). It only makes more sense to leave a synctask's state to the synctask library, since its an internal affair. * Need to 'yawn' before 'yield' to avoid re-running tasks to set task->woken appropriately. Change-Id: Ic7a59e6ebcc46f03e53223ca237668d45a3cba40 BUG: 948686 Signed-off-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/4985 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/syncop.c | 5 +++++ libglusterfs/src/syncop.h | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 98aee98d..27518057 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -89,6 +89,8 @@ synctask_yield (struct synctask *task) task->proc->sched.uc_flags &= ~_UC_TLSBASE; #endif + if (task->state != SYNCTASK_DONE) + task->state = SYNCTASK_SUSPEND; if (swapcontext (&task->ctx, &task->proc->sched) < 0) { gf_log ("syncop", GF_LOG_ERROR, "swapcontext failed (%s)", strerror (errno)); @@ -238,6 +240,7 @@ synctask_new (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, newtask->gid = newtask->opframe->root->gid; INIT_LIST_HEAD (&newtask->all_tasks); + INIT_LIST_HEAD (&newtask->waitq); if (getcontext (&newtask->ctx) < 0) { gf_log ("syncop", GF_LOG_ERROR, @@ -530,6 +533,7 @@ __synclock_lock (struct synclock *lock) /* called within a synctask */ list_add_tail (&task->waitq, &lock->waitq); pthread_mutex_unlock (&lock->guard); + synctask_yawn (task); synctask_yield (task); /* task is removed from waitq in unlock, * under lock->guard.*/ @@ -686,6 +690,7 @@ __syncbarrier_wait (struct syncbarrier *barrier, int waitfor) list_add_tail (&task->waitq, &barrier->waitq); { pthread_mutex_unlock (&barrier->guard); + synctask_yawn (task); synctask_yield (task); pthread_mutex_lock (&barrier->guard); } diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index 7ede9663..5c439f85 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -210,8 +210,6 @@ struct syncargs { \ STACK_WIND_COOKIE (frame, cbk, (void *)stb, subvol, \ op, params); \ - if (task) \ - task->state = SYNCTASK_SUSPEND; \ \ __yield (stb); \ if (task) \ -- cgit