2013-12-09 10:59:57 +00:00
|
|
|
#ifndef PARALLELWORK_H
|
|
|
|
#define PARALLELWORK_H
|
|
|
|
|
|
|
|
#include "system_global.h"
|
|
|
|
|
|
|
|
#define PARALLEL_MAX_THREADS 20
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace system {
|
|
|
|
|
|
|
|
class SYSTEMSHARED_EXPORT ParallelWork
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef int (*ParallelUnitFunction)(ParallelWork* work, int unit, void* data);
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PARALLEL_WORKER_STATUS_VOID,
|
|
|
|
PARALLEL_WORKER_STATUS_RUNNING,
|
|
|
|
PARALLEL_WORKER_STATUS_DONE
|
|
|
|
} ParallelWorkerStatus;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Thread* thread;
|
2014-08-18 10:17:16 +00:00
|
|
|
ParallelWorker* worker;
|
2013-12-09 10:59:57 +00:00
|
|
|
ParallelWorkerStatus status;
|
|
|
|
int unit;
|
|
|
|
int result;
|
2014-08-18 10:17:16 +00:00
|
|
|
} ParallelWorkerThread;
|
2013-12-09 10:59:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a parallel work handler.
|
|
|
|
*
|
2014-08-18 10:17:16 +00:00
|
|
|
* This will spawn a number of threads.
|
|
|
|
*/
|
|
|
|
ParallelWork(ParallelWorker *worker, int units);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a parallel work handler.
|
2013-12-09 10:59:57 +00:00
|
|
|
*
|
2014-08-18 10:17:16 +00:00
|
|
|
* This is a compatibility constructor for older code, use the constructor with ParallelWorker instead.
|
2013-12-09 10:59:57 +00:00
|
|
|
*/
|
|
|
|
ParallelWork(ParallelUnitFunction func, int units, void* data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a parallel work handler.
|
|
|
|
*
|
|
|
|
* The work must be terminated or fully interrupted before calling this.
|
|
|
|
*/
|
|
|
|
~ParallelWork();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start working on the units.
|
|
|
|
*
|
2014-08-18 10:17:16 +00:00
|
|
|
* @param threads Number of threads to spaws, -1 for an optimal number.
|
2013-12-09 10:59:57 +00:00
|
|
|
*/
|
2014-08-18 10:17:16 +00:00
|
|
|
int perform(int thread_count=-1);
|
2013-12-09 10:59:57 +00:00
|
|
|
|
|
|
|
int units;
|
|
|
|
int running;
|
2014-08-18 10:17:16 +00:00
|
|
|
ParallelWorker *worker;
|
|
|
|
bool worker_compat;
|
|
|
|
ParallelWorkerThread threads[PARALLEL_MAX_THREADS];
|
2013-12-09 10:59:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PARALLELWORK_H
|