66 lines
1.7 KiB
C
Executable File
66 lines
1.7 KiB
C
Executable File
#ifndef _THREADPOOL_H_
|
|
#define _THREADPOOL_H_
|
|
#include "kpacket.h"
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
typedef void *(*thread_routine)(void *param);
|
|
|
|
/**
|
|
* @file threadpool.h
|
|
* @brief Threadpool Header File
|
|
*/
|
|
|
|
/**
|
|
* Increase this constants at your own risk
|
|
* Large values might slow down your system
|
|
*/
|
|
#define MAX_THREADS 16
|
|
|
|
typedef struct threadpool_s threadpool;
|
|
|
|
/**
|
|
* @function threadpool_create
|
|
* @brief Creates a threadpool object.
|
|
* @param thread_count Number of worker threads.
|
|
* @param queue_size Size of the queue(routine) for threadpool.
|
|
* @return a newly created thread pool or NULL
|
|
*/
|
|
threadpool *threadpool_create(uint32_t max_thread_cnt);
|
|
|
|
/**
|
|
* @function threadpool_add
|
|
* @brief add a new task in the queue of a thread pool
|
|
* @param pool Thread pool to which add the task.
|
|
* @param function Pointer to the function that will perform the task.
|
|
* @param packet Packet to be passed to the function.
|
|
* @return 0 if all goes well, negative values in case of error (@see
|
|
* threadpool_error_t for codes).
|
|
*/
|
|
uint32_t threadpool_add(threadpool *pool, thread_routine routine, kpacket *packet);
|
|
|
|
|
|
//delete a routine
|
|
uint32_t threadpool_del(threadpool *pool, thread_routine routine);
|
|
|
|
/**
|
|
* @function threadpool_destroy
|
|
* @brief Stops and destroys a thread pool.
|
|
* @param pool Thread pool to destroy.
|
|
*
|
|
* 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.
|
|
*/
|
|
uint32_t threadpool_destroy(threadpool *pool);
|
|
|
|
void threadpool_dump(threadpool *pool);
|
|
|
|
void threadpool_test();
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _THREADPOOL_H_ */
|