Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
thpool.h File Reference

this file Defines everything related to ThreadPool More...

Go to the source code of this file.

Data Structures

struct  SNF_ThreadPool_work_t
 Defines the 'work' needed to do by defining a 'func'tion and it's 'arg'ument. More...
 
struct  SNF_ThreadPool_worker_t
 Defines the 'worker'that would handle a certain 'work'. More...
 
struct  SNF_ThreadPool_t
 The structure for a Thread Pool. More...
 

Typedefs

typedef struct SNF_ThreadPool_work_t SNF_thpool_work
 
typedef struct SNF_ThreadPool_worker_t SNF_thpool_worker
 
typedef struct SNF_ThreadPool_t thpool
 

Functions

int snf_thpool_inis (thpool **ThreadPool, int Max_Threads, void *(*Main_Worker)(), void *arg)
 Insitanciates a new thread pool, with a Limiter ( Max_Threads )
 
void snf_thpool_addwork (thpool *pool, void *(*func)(), void *arg)
 Creates a "work" that will call the func function with argument arg
 
void snf_thpool_wait (thpool *pool)
 Blocks current thread until there is No "Worker" is working and no "work" is waiting in queue.
 
void snf_thpool_join (thpool *pool)
 Will Block till the Main_worker finishes.
 
void snf_thpool_stop (thpool *pool)
 will stop creating "workers" and wait till all already exising "workers" finish their "work"
 

Detailed Description

this file Defines everything related to ThreadPool

Thread Pools By Abdelhadi Seddar This implemantation of a Threadpool is by no means perfect nor optimized, because I made it based of a graph depicting how a threadpool works, without seeing any documentation about it, this is just a learning experience for me and im learning through trial and error

Typedef Documentation

◆ SNF_thpool_work

◆ SNF_thpool_worker

◆ thpool

typedef struct SNF_ThreadPool_t thpool

Function Documentation

◆ snf_thpool_inis()

int snf_thpool_inis ( thpool ** ThreadPool,
int Max_Threads,
void *(* Main_Worker )(),
void * arg )
extern

Insitanciates a new thread pool, with a Limiter ( Max_Threads )

Parameters
ThreadPoolReturns the thread pool by writes the newly created instance in the pointer given in this parameter
Max_ThreadsMaximum Total allowed threads ( Must be 2+ if No Main Worker given, else must me 3+ for proper work)
Main_WorkerMain Function that would be called upon finishing the intialisation of the
argthe argument that would be given to the Main_worker function.
Returns
0 On Success || -1 On fail { Shall fail only if 1 - ThreadPool is NULL || 2 - Max_Thread is below recommended/required value }

◆ snf_thpool_addwork()

void snf_thpool_addwork ( thpool * pool,
void *(* func )(),
void * arg )
extern

Creates a "work" that will call the func function with argument arg

Parameters
poolThe Thead Pool to be operated on.
funcThe function that would be called once a "worker" picks up the "work".
argargument to be given to the func upon call.

◆ snf_thpool_wait()

void snf_thpool_wait ( thpool * pool)
extern

Blocks current thread until there is No "Worker" is working and no "work" is waiting in queue.

Parameters
poolThe Thead Pool to be operated on.

◆ snf_thpool_join()

void snf_thpool_join ( thpool * pool)
extern

Will Block till the Main_worker finishes.

Parameters
poolThe Thead Pool to be operated on.

◆ snf_thpool_stop()

void snf_thpool_stop ( thpool * pool)
extern

will stop creating "workers" and wait till all already exising "workers" finish their "work"

Parameters
poolThe Thead Pool to be operated on.