diff --git a/include/fc/thread/thread.hpp b/include/fc/thread/thread.hpp index bbd8317..931a9fe 100644 --- a/include/fc/thread/thread.hpp +++ b/include/fc/thread/thread.hpp @@ -12,7 +12,7 @@ namespace fc { namespace detail { - class pool_impl; + class worker_pool; void* get_thread_specific_data(unsigned slot); void set_thread_specific_data(unsigned slot, void* new_value, void(*cleanup)(void*)); unsigned get_next_unused_task_storage_slot(); @@ -152,7 +152,7 @@ namespace fc { friend class task_base; friend class thread_d; friend class mutex; - friend class detail::pool_impl; + friend class detail::worker_pool; friend void* detail::get_thread_specific_data(unsigned slot); friend void detail::set_thread_specific_data(unsigned slot, void* new_value, void(*cleanup)(void*)); friend unsigned detail::get_next_unused_task_storage_slot(); diff --git a/src/thread/parallel.cpp b/src/thread/parallel.cpp index 83ef647..dfa85c3 100644 --- a/src/thread/parallel.cpp +++ b/src/thread/parallel.cpp @@ -84,24 +84,23 @@ namespace fc { }); } - void post( task_base* task ) + thread* post( task_base* task ) { idle_notifier_impl* ini; while( idle_threads.pop( ini ) ) if( ini->is_idle.exchange( false ) ) { // minor race condition here, a thread might receive a task while it's busy - threads[ini->id]->async_task( task, priority() ); - return; + return threads[ini->id]; } boost::unique_lock lock(pool_lock); while( idle_threads.pop( ini ) ) if( ini->is_idle.exchange( false ) ) { // minor race condition here, a thread might receive a task while it's busy - threads[ini->id]->async_task( task, priority() ); - return; + return threads[ini->id]; } while( !waiting_tasks.push( task ) ) elog( "Worker pool internal error" ); + return 0; } task_base* enqueue_idle_thread( idle_notifier_impl* ini ) @@ -145,7 +144,9 @@ namespace fc { void worker_pool::post( task_base* task ) { - my->post( task ); + thread* worker = my->post( task ); + if( worker ) + worker->async_task( task, priority() ); } worker_pool& get_worker_pool()