144extern void snf_thpool_destroy(
SNF_thpool **pool);
Main Header FileThis File Calls for all the header files exisitng in this library,...
The structure for a Thread Pool.
Definition thpool.h:69
sem_t thpool_status_sem
Definition thpool.h:106
pthread_mutex_t thpool_workers_MUTEX
Used to synchronize the acces to thpool_workers.
Definition thpool.h:83
int thpool_n_workers
Limiter for the amount of threads that could be created.
Definition thpool.h:99
SNF_thpool_worker * thpool_workers
This LinkedList will store the currently working "workers" or more exactly the worker thread info.
Definition thpool.h:77
pthread_mutex_t thpool_status_MUTEX
Definition thpool.h:104
pthread_mutex_t thpool_noworks_MUTEX
Used to synchronize if all "works" are handled and all "workers" had finished their assigned "work" S...
Definition thpool.h:87
pthread_t * thpool_main_worker
The main function that is runs first when the Thread pool has started.
Definition thpool.h:91
pthread_mutex_t thpool_works_MUTEX
Used to synchronize the acces to thpool_works.
Definition thpool.h:80
sem_t thpool_workers_sem
Semaphore used for synchronization; Used primarly to notify the conclusion of "workers" to the Thread...
Definition thpool.h:96
SNF_thpool_status thpool_status
If set = 1 the thpool_handler will stop creating "workers" and wait till all already exising "workers...
Definition thpool.h:103
pthread_t * thpool_handler
Thread that manages "workers" and assign their "work" to them.
Definition thpool.h:89
pthread_cond_t thpool_status_COND
Definition thpool.h:105
sem_t thpool_works_sem
This is the semaphore for handling.
Definition thpool.h:73
SNF_thpool_work * thpool_works
This LinkedList will store the "works" or "jobs".
Definition thpool.h:71
Defines the 'work' needed to do by defining a 'func'tion and it's 'arg'ument.
Definition thpool.h:51
SNF_thpool * pool
the source Thread Pool
Definition thpool.h:57
SNF_thpool_work * next
Saves the next work ( Linked List )
Definition thpool.h:59
void * arg
the argument to be given upon execution
Definition thpool.h:55
Defines the 'worker'that would handle a certain 'work'.
Definition thpool.h:63
pthread_t worker
The worker's thread id.
Definition thpool.h:65
enum SNF_ThreadPool_Status_e SNF_thpool_status
Definition thpool.h:33
void snf_thpool_stop(SNF_thpool *pool)
will order the Thread Pool to stop.
void snf_thpool_wait(SNF_thpool *pool)
Blocks current thread until the Thread Pool's last changed status has taken effect.
time_t SNF_THPOOL_STOPWAIT
This defines the amount of seconds to wait a worker to stop, if the worker does not stop during this ...
int snf_thpool_inis(SNF_thpool **ThreadPool, int Max_Threads, void *(*Main_Worker)(void *), void *arg)
Insitanciates a new thread pool, with a Limiter ( Max_Threads )
void snf_thpool_run(SNF_thpool *pool)
void snf_thpool_addwork(SNF_thpool *pool, void *(*func)(), void *arg)
Creates a "work" that will call the func function with argument arg
SNF_ThreadPool_Status_e
Definition thpool.h:36
@ SNF_THPOOL_RUN
Used to Signify that the Thread Pool is running or been ordred to.
Definition thpool.h:43
@ SNF_THPOOL_DESTROY
Used to Signify that the Thread Pool is being ordred to be destroyied.
Definition thpool.h:46
@ SNF_THPOOL_STOP
Used to Signify that the Thread Pool was stopped or been ordred to.
Definition thpool.h:40
void snf_thpool_join(SNF_thpool *pool)
Will Block till the Main_worker finishes.