libsheepy
/home/rlp/git/sw/libsheepy/release/tpool.h

Initialize threadpoolInitializes a threadpool. This function will not return untill all threads have initialized successfully.

.. threadpool tpool; //First we declare a threadpool tpool = tpool_init(4); //then we initialize it to 4 threads ..

Parameters
num_threadsnumber of threads to be created in the threadpool
Returns
threadpool created threadpool on success, NULL on error
/**********************************
* @author Johan Hanssen Seferidis
* License: MIT
*
**********************************/
#pragma once
#if (__OpenBSD__)
// have to include pthread.h for pthread_mutex_t in OpenBSD with GCC 4.9.4
#include "pthread.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
// locks, max 512 threads
#define tpoolLockCount 512
extern pthread_mutex_t tpoolLocks[tpoolLockCount]; // only one thread can have the lock
// use lock in the tpoolLocks array
void tpoolLock(int position);
// unlock a lock in the tpoolLocks array
void tpoolUlock(int position);
typedef struct {
union {
char *s;
};
union {
char *s2;
};
// return value
union {
char **list;
int status;
};
void (*cb)(void*);
void *cbArgs;
void *channel;
#define tpoolAdd(task, args) tpool_add_work(tpool, task, args)
#define tpoolWait tpool_wait(tpool)
#define tpoolKill tpool_destroy(tpool)
#define tpoolPause tpool_pause(tpool)
#define tpoolResume tpool_resume(tpool)
#define tpoolNum tpool_num_threads_working(tpool)
/* =================================== API ======================================= */
typedef struct tpool_* threadpool;
extern threadpool tpool;
threadpool tpool_init(int num_threads);
int tpool_add_work(threadpool, void (*function_p)(void*), void* arg_p);
void tpool_wait(threadpool);
void tpool_pause(threadpool);
void tpool_resume(threadpool);
void tpool_destroy(threadpool);
int tpool_num_threads_working(threadpool);
#ifdef __cplusplus
}
#endif