mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Missing files
This commit is contained in:
35
CThreadHelper.cpp
Normal file
35
CThreadHelper.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "CThreadHelper.h"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
CThreadHelper::CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads)
|
||||
{
|
||||
currentTask = 0; amount = Tasks->size();
|
||||
tasks = Tasks;
|
||||
threads = Threads;
|
||||
}
|
||||
void CThreadHelper::run()
|
||||
{
|
||||
boost::thread_group grupa;
|
||||
for(int i=0;i<threads;i++)
|
||||
grupa.create_thread(boost::bind(&CThreadHelper::processTasks,this));
|
||||
grupa.join_all();
|
||||
}
|
||||
void CThreadHelper::processTasks()
|
||||
{
|
||||
int pom;
|
||||
while(true)
|
||||
{
|
||||
rtinm.lock();
|
||||
if((pom=currentTask) >= amount)
|
||||
{
|
||||
rtinm.unlock();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
++currentTask;
|
||||
rtinm.unlock();
|
||||
(*tasks)[pom]();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user