void ThreadPool::do_job(ThreadPool::TaskType& task, unique_lock< mutex >& exclusion)
 {
   exclusion.unlock();
   //__sync_synchronize();
   auto start = std::chrono::system_clock::now();
   string account = task.account;
   auto task_future = task.task.get_future();
   task.task();
   try
   {
     task_future.get();
   }
   catch(std::exception&e)
   {
     log_file << "Exception thrown in job: " << e.what() << endl;
     breakpoint();
   }
   catch(...)
   {
     log_file << "Exception thrown... but it's a mystery... results undefined" << endl;
     breakpoint();
   }
   auto end = std::chrono::system_clock::now();
   int elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>
                         (end-start).count();
   //atomic_thread_fence(std::memory_order_seq_cst);
   //__sync_synchronize();
   exclusion.lock();
   accounts[account] += elapsed_seconds;
   work_queue_changed.notify_all();
 }
Exemplo n.º 2
0
double SpriteQueue::DoLoad(unique_lock<mutex> &lock) const
{
	for(int i = 0; !toLoad.empty() && i < 30; ++i)
	{
		Item item = toLoad.front();
		toLoad.pop();
		
		lock.unlock();
		
		item.sprite->AddFrame(item.frame, item.image, item.mask);
		
		lock.lock();
		++completed;
	}
	
	// Wait until we have completed loading of as many sprites as we have added.
	// The value of "added" is protected by readMutex.
	unique_lock<mutex> readLock(readMutex);
	// Special cases: we're bailing out, or we are done.
	if(added <= 0 || added == completed)
		return 1.;
	return static_cast<double>(completed) / static_cast<double>(added);
}