FC Updates from BitShares and myself #21

Closed
nathanielhourt wants to merge 687 commits from dapp-support into latest-fc
2 changed files with 9 additions and 8 deletions
Showing only changes of commit d0b280aca7 - Show all commits

View file

@ -12,7 +12,7 @@ namespace fc {
namespace detail namespace detail
{ {
class pool_impl; class worker_pool;
void* get_thread_specific_data(unsigned slot); void* get_thread_specific_data(unsigned slot);
void set_thread_specific_data(unsigned slot, void* new_value, void(*cleanup)(void*)); void set_thread_specific_data(unsigned slot, void* new_value, void(*cleanup)(void*));
unsigned get_next_unused_task_storage_slot(); unsigned get_next_unused_task_storage_slot();
@ -152,7 +152,7 @@ namespace fc {
friend class task_base; friend class task_base;
friend class thread_d; friend class thread_d;
friend class mutex; 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::get_thread_specific_data(unsigned slot);
friend void detail::set_thread_specific_data(unsigned slot, void* new_value, void(*cleanup)(void*)); friend void detail::set_thread_specific_data(unsigned slot, void* new_value, void(*cleanup)(void*));
friend unsigned detail::get_next_unused_task_storage_slot(); friend unsigned detail::get_next_unused_task_storage_slot();

View file

@ -84,24 +84,23 @@ namespace fc {
}); });
} }
void post( task_base* task ) thread* post( task_base* task )
{ {
idle_notifier_impl* ini; idle_notifier_impl* ini;
while( idle_threads.pop( ini ) ) while( idle_threads.pop( ini ) )
if( ini->is_idle.exchange( false ) ) if( ini->is_idle.exchange( false ) )
{ // minor race condition here, a thread might receive a task while it's busy { // minor race condition here, a thread might receive a task while it's busy
threads[ini->id]->async_task( task, priority() ); return threads[ini->id];
return;
} }
boost::unique_lock<fc::spin_yield_lock> lock(pool_lock); boost::unique_lock<fc::spin_yield_lock> lock(pool_lock);
while( idle_threads.pop( ini ) ) while( idle_threads.pop( ini ) )
if( ini->is_idle.exchange( false ) ) if( ini->is_idle.exchange( false ) )
{ // minor race condition here, a thread might receive a task while it's busy { // minor race condition here, a thread might receive a task while it's busy
threads[ini->id]->async_task( task, priority() ); return threads[ini->id];
return;
} }
while( !waiting_tasks.push( task ) ) while( !waiting_tasks.push( task ) )
elog( "Worker pool internal error" ); elog( "Worker pool internal error" );
return 0;
} }
task_base* enqueue_idle_thread( idle_notifier_impl* ini ) task_base* enqueue_idle_thread( idle_notifier_impl* ini )
@ -145,7 +144,9 @@ namespace fc {
void worker_pool::post( task_base* task ) 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() worker_pool& get_worker_pool()