30 bool remainingTasksToComplete =
true;
32 while (isRunning() && !
_bToEnd && remainingTasksToComplete)
46 task->_running =
true;
52 task->_running =
false;
53 task->_completed =
true;
65 remainingTasksToComplete =
false;
70 OTask::OTask() : _running(false), _completed(false), _canceled(false) {}
107 for (
unsigned int i = 0; i < slaves; ++i)
123 task->_completed =
true;
124 task->_canceled =
true;
129 for (i = 0; i < size(); ++i)
131 (*this)[i]->_bToEnd =
true;
132 (*this)[i]->terminate();
139 for (i = 0; i < size(); ++i)
179 for (
unsigned int i = 0; i < size(); ++i)
181 (*this)[i]->_bToEnd =
false;
188 std::vector<OSlaveThread*>& threads =
static_cast<std::vector<OSlaveThread*>&
>(*this);
202 for (
size_t i = 0; i <
_tasks.size(); ++i)
210 task->_canceled =
true;
217 for (
unsigned int i = 0; i < size(); ++i)
219 (*this)[i]->_bToEnd =
true;
This class defines a thread for running tasks in a threads collection. Slave thread for the threads c...
OThreadPool * _pool
Pointer on the parent threads collection.
~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.
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.
OTask()
Default constructor.
bool _canceled
Cancel flag.
Slave threads collection.
unsigned int _totalCount
Total number of tasks to run.
std::queue< LPOTask > _tasks
Tasks queue.
unsigned int getTotalCount() const
Return the total number of tasks.
void begin(unsigned int count)
Begin solver.
OThreadPool(unsigned int slaves)
Build a threads collection and allocate "slaves" thread.
virtual ~OThreadPool()
Destructor.
unsigned int _counter
Total number of ended tasks.
unsigned int getCount() const
Return the counter.
void stop()
Cancel the pending tasks.
virtual void push(OTask *task)
Add a task to the queue.
friend class OSlaveThread
#define TY_LOCK_SHARED_MUTEX(name)
#define TY_UNLOCK_SHARED_MUTEX(name)
#define TY_OMUTEXLOCKER_SHARED_MUTEX(name)