From 05ec2f808a73f1042dc1a228fa7dc1822c46b07f Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Thu, 12 Mar 2015 11:23:55 +0100 Subject: [PATCH] mtapi_c: only notify workers if they are actually sleeping --- mtapi_c/src/embb_mtapi_scheduler_t.c | 8 ++++++-- mtapi_c/src/embb_mtapi_thread_context_t.c | 1 + mtapi_c/src/embb_mtapi_thread_context_t.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mtapi_c/src/embb_mtapi_scheduler_t.c b/mtapi_c/src/embb_mtapi_scheduler_t.c index 5e9bf4c..28cc5ce 100644 --- a/mtapi_c/src/embb_mtapi_scheduler_t.c +++ b/mtapi_c/src/embb_mtapi_scheduler_t.c @@ -356,12 +356,14 @@ int embb_mtapi_scheduler_worker(void * arg) { counter++; } else { /* no work, go to sleep */ + embb_atomic_store_int(&thread_context->is_sleeping, 1); embb_mutex_lock(&thread_context->work_available_mutex); embb_condition_wait_for( &thread_context->work_available, &thread_context->work_available_mutex, &sleep_duration); embb_mutex_unlock(&thread_context->work_available_mutex); + embb_atomic_store_int(&thread_context->is_sleeping, 0); } } @@ -593,8 +595,10 @@ mtapi_boolean_t embb_mtapi_scheduler_schedule_task( if (pushed) { /* signal the worker thread a task was pushed to */ - embb_condition_notify_one( - &scheduler->worker_contexts[ii].work_available); + if (embb_atomic_load_int(&scheduler->worker_contexts[ii].is_sleeping)) { + embb_condition_notify_one( + &scheduler->worker_contexts[ii].work_available); + } } else { /* task could not be launched */ embb_atomic_fetch_and_add_int(&local_action->num_tasks, -1); diff --git a/mtapi_c/src/embb_mtapi_thread_context_t.c b/mtapi_c/src/embb_mtapi_thread_context_t.c index ea5d4d1..2a7bdc4 100644 --- a/mtapi_c/src/embb_mtapi_thread_context_t.c +++ b/mtapi_c/src/embb_mtapi_thread_context_t.c @@ -70,6 +70,7 @@ void embb_mtapi_thread_context_initialize_with_node_worker_and_core( embb_mutex_init(&that->work_available_mutex, EMBB_MUTEX_PLAIN); embb_condition_init(&that->work_available); + embb_atomic_store_int(&that->is_sleeping, 0); } mtapi_boolean_t embb_mtapi_thread_context_start( diff --git a/mtapi_c/src/embb_mtapi_thread_context_t.h b/mtapi_c/src/embb_mtapi_thread_context_t.h index 0ed2dd3..a207886 100644 --- a/mtapi_c/src/embb_mtapi_thread_context_t.h +++ b/mtapi_c/src/embb_mtapi_thread_context_t.h @@ -56,6 +56,7 @@ struct embb_mtapi_thread_context_struct { embb_condition_t work_available; embb_thread_t thread; embb_tss_t tss_id; + embb_atomic_int is_sleeping; embb_mtapi_node_t* node; embb_mtapi_task_queue_t** queue; -- libgit2 0.26.0