Concord - C Discord API library
A Discord API wrapper library written in C
threadpool.h File Reference

Threadpool Header File. More...

Go to the source code of this file.

Macros

#define MAX_THREADS   64
 
#define MAX_QUEUE   65536
 

Typedefs

typedef struct threadpool_t threadpool_t
 

Enumerations

enum  threadpool_error_t {
  threadpool_invalid = -1 , threadpool_lock_failure = -2 , threadpool_queue_full = -3 , threadpool_shutdown = -4 ,
  threadpool_thread_failure = -5
}
 
enum  threadpool_destroy_flags_t { threadpool_graceful = 1 }
 

Functions

threadpool_tthreadpool_create (int thread_count, int queue_size, int flags)
 Creates a threadpool_t object. More...
 
int threadpool_add (threadpool_t *pool, void(*routine)(void *), void *arg, int flags)
 add a new task in the queue of a thread pool More...
 
int threadpool_destroy (threadpool_t *pool, int flags)
 Stops and destroys a thread pool. More...
 

Detailed Description

Threadpool Header File.

Macro Definition Documentation

◆ MAX_THREADS

#define MAX_THREADS   64

Increase this constants at your own risk Large values might slow down your system

◆ MAX_QUEUE

#define MAX_QUEUE   65536

Typedef Documentation

◆ threadpool_t

typedef struct threadpool_t threadpool_t

Enumeration Type Documentation

◆ threadpool_error_t

Enumerator
threadpool_invalid 
threadpool_lock_failure 
threadpool_queue_full 
threadpool_shutdown 
threadpool_thread_failure 

◆ threadpool_destroy_flags_t

Enumerator
threadpool_graceful 

Function Documentation

◆ threadpool_create()

threadpool_t * threadpool_create ( int  thread_count,
int  queue_size,
int  flags 
)

Creates a threadpool_t object.

@function threadpool_create

Parameters
thread_countNumber of worker threads.
queue_sizeSize of the queue.
flagsUnused parameter.
Returns
a newly created thread pool or NULL

◆ threadpool_add()

int threadpool_add ( threadpool_t pool,
void(*)(void *)  routine,
void *  arg,
int  flags 
)

add a new task in the queue of a thread pool

@function threadpool_add

Parameters
poolThread pool to which add the task.
functionPointer to the function that will perform the task.
argumentArgument to be passed to the function.
flagsUnused parameter.
Returns
0 if all goes well, negative values in case of error (
See also
threadpool_error_t for codes).

◆ threadpool_destroy()

int threadpool_destroy ( threadpool_t pool,
int  flags 
)

Stops and destroys a thread pool.

@function threadpool_destroy

Parameters
poolThread pool to destroy.
flagsFlags for shutdown

Known values for flags are 0 (default) and threadpool_graceful in which case the thread pool doesn't accept any new tasks but processes all pending tasks before shutdown.