Commit 05ec2f80 by Marcus Winter

mtapi_c: only notify workers if they are actually sleeping

parent 7f7e33d2
...@@ -356,12 +356,14 @@ int embb_mtapi_scheduler_worker(void * arg) { ...@@ -356,12 +356,14 @@ int embb_mtapi_scheduler_worker(void * arg) {
counter++; counter++;
} else { } else {
/* no work, go to sleep */ /* no work, go to sleep */
embb_atomic_store_int(&thread_context->is_sleeping, 1);
embb_mutex_lock(&thread_context->work_available_mutex); embb_mutex_lock(&thread_context->work_available_mutex);
embb_condition_wait_for( embb_condition_wait_for(
&thread_context->work_available, &thread_context->work_available,
&thread_context->work_available_mutex, &thread_context->work_available_mutex,
&sleep_duration); &sleep_duration);
embb_mutex_unlock(&thread_context->work_available_mutex); 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( ...@@ -593,8 +595,10 @@ mtapi_boolean_t embb_mtapi_scheduler_schedule_task(
if (pushed) { if (pushed) {
/* signal the worker thread a task was pushed to */ /* signal the worker thread a task was pushed to */
embb_condition_notify_one( if (embb_atomic_load_int(&scheduler->worker_contexts[ii].is_sleeping)) {
&scheduler->worker_contexts[ii].work_available); embb_condition_notify_one(
&scheduler->worker_contexts[ii].work_available);
}
} else { } else {
/* task could not be launched */ /* task could not be launched */
embb_atomic_fetch_and_add_int(&local_action->num_tasks, -1); embb_atomic_fetch_and_add_int(&local_action->num_tasks, -1);
......
...@@ -70,6 +70,7 @@ void embb_mtapi_thread_context_initialize_with_node_worker_and_core( ...@@ -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_mutex_init(&that->work_available_mutex, EMBB_MUTEX_PLAIN);
embb_condition_init(&that->work_available); embb_condition_init(&that->work_available);
embb_atomic_store_int(&that->is_sleeping, 0);
} }
mtapi_boolean_t embb_mtapi_thread_context_start( mtapi_boolean_t embb_mtapi_thread_context_start(
......
...@@ -56,6 +56,7 @@ struct embb_mtapi_thread_context_struct { ...@@ -56,6 +56,7 @@ struct embb_mtapi_thread_context_struct {
embb_condition_t work_available; embb_condition_t work_available;
embb_thread_t thread; embb_thread_t thread;
embb_tss_t tss_id; embb_tss_t tss_id;
embb_atomic_int is_sleeping;
embb_mtapi_node_t* node; embb_mtapi_node_t* node;
embb_mtapi_task_queue_t** queue; embb_mtapi_task_queue_t** queue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment