46 task->_running =
true;
52 task->_running =
false;
53 task->_completed =
true;
67 OTask::OTask() : _running(false), _completed(false), _canceled(false) {}
104 for (
unsigned int i = 0; i < slaves; ++i)
116 while (!_tasks.empty())
120 task->_completed =
true;
121 task->_canceled =
true;
126 for (i = 0; i < size(); ++i)
128 (*this)[i]->_bToEnd =
true;
129 (*this)[i]->terminate();
136 for (i = 0; i < size(); ++i)
176 for (
unsigned int i = 0; i < size(); ++i)
178 (*this)[i]->_bToEnd =
false;
185 unsigned int totalCount = getTotalCount();
187 unsigned int last = 0;
188 while (last < totalCount)
190 unsigned int current = getCount();
203 for (
size_t i = 0; i < _tasks.size(); ++i)
211 task->_canceled =
true;
218 for (
unsigned int i = 0; i < size(); ++i)
220 (*this)[i]->_bToEnd =
true;
226 while (getCount() < getTotalCount())
#define TY_LOCK_SHARED_MUTEX(name)
#define TY_UNLOCK_SHARED_MUTEX(name)
#define TY_OMUTEXLOCKER_SHARED_MUTEX(name)
This class defines a thread for running tasks in a threads collection. Slave thread for the threads c...
~OSlaveThread()
Destroy the slave thread; wait for the end of the thread.
OSlaveThread(OThreadPool *pool)
Build a slave thread for a threads collection.
void run()
Run a waiting task.
OThreadPool * _pool
Pointer on the parent threads collection.
static void msleep(unsigned long msecs)
Task of a threads collection.
bool isCanceled() const
Return true if the task has been cancelled, false otherwise.
void reset()
Reset the task status (_running=false and _completed=false)
bool _running
Running flag.
bool isCompleted() const
Return true if the task is completed, false otherwise.
bool isRunning() const
Return true if the task is running, false otherwise.
bool _completed
Completed flag.
virtual ~OTask()
Destructor : waits for the end of the task to destroy it.
friend class OSlaveThread
OTask()
Default constructor.
bool _canceled
Cancel flag.
Slave threads collection.
void begin(unsigned int count)
Begin solver.
virtual ~OThreadPool()
Destructor.
unsigned int _counter
Total number of ended tasks.
std::queue< LPOTask > _tasks
Tasks queue.
unsigned int getCount() const
Return the counter.
void stop()
Cancel the pending tasks.
virtual void push(OTask *task)
Add a task to the queue.