1 #ifndef INCLUDE_AL_THREAD_HPP
2 #define INCLUDE_AL_THREAD_HPP
61 typedef void *(*CFunc)(
void *userData);
67 :
func(threadFunc),
user(userData) {}
88 Thread(
void *(*cFunc)(
void *userData),
void *userData);
111 bool start(
void *(*threadFunc)(
void *userData),
void *userData);
142 template <
class ThreadFunction>
class Threads {
156 int size()
const {
return mSize; }
169 for (
int i = 0; i <
size(); ++i) {
178 for (
int i = 0; i <
size(); ++i)
209 double left = diam * i +
min;
211 interval[1] = left + diam;
227 inline bool Thread::start(
void *(*threadFunc)(
void *userData),
void *userData) {
228 mCFunc.
func = threadFunc;
229 mCFunc.
user = userData;
230 return start(mCFunc);
Thread(const Thread &other)
Copy constructor.
Thread()
Create thread without starting.
Thread(void *(*cFunc)(void *userData), void *userData)
static void * current()
Return pointer to current OS thread object.
bool start(ThreadFunction &func)
Start executing thread function.
bool join()
Block the calling routine indefinitely until the thread terminates.
Thread(ThreadFunction &func)
Thread & priority(int v)
Set thread priority.
Thread & joinOnDestroy(bool v)
Set whether thread will automatically join upon destruction.
Thread & thread(int i)
Get a worker thread.
Worker & worker(int i)
Get a worker.
void join()
Join all worker threads.
void start(bool joinAll=true)
Start all worker threads.
int size() const
Returns number of workers.
double range(T max, T min=T(0))
Get worker sub-interval range of a full interval [min, max)
void resize(int n)
Resize number of workers.
void getInterval(T *interval, int i, T max, T min=T(0))
Get worker sub-interval of a full interval [min, max)
T min(const T &v1, const T &v2, const T &v3)
T max(const T &v1, const T &v2, const T &v3)
C-style thread function with user data.
void *(* CFunc)(void *userData)
Prototype of thread execution function.
CThreadFunction(CFunc threadFunc=0, void *userData=0)
void operator()()
Routine called on thread execution start.
void * user
User data passed into thread execution function.
CFunc func
Thread execution function.
Function object interface used by thread.
virtual void operator()()=0
Routine called on thread execution start.