2013-12-23 13:09:52 +00:00
|
|
|
#ifndef PARALLELPOOL_H
|
|
|
|
#define PARALLELPOOL_H
|
|
|
|
|
|
|
|
#include "system_global.h"
|
|
|
|
|
2015-11-18 18:37:00 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2013-12-23 13:09:52 +00:00
|
|
|
namespace paysages {
|
|
|
|
namespace system {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Pool to handle a group of threads doing the same task.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class SYSTEMSHARED_EXPORT ParallelPool {
|
|
|
|
public:
|
2013-12-23 13:09:52 +00:00
|
|
|
ParallelPool();
|
|
|
|
virtual ~ParallelPool();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Start the effective work.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
void start(int thread_count = -1);
|
2013-12-23 13:09:52 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Method called from each thread to do actual work.
|
|
|
|
*/
|
|
|
|
virtual void work() = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Method called once to interrupt all threads.
|
|
|
|
*/
|
|
|
|
virtual void interrupt();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
protected:
|
2013-12-23 13:09:52 +00:00
|
|
|
bool running;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-12-10 23:36:50 +00:00
|
|
|
vector<Thread *> threads;
|
2013-12-23 13:09:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PARALLELPOOL_H
|