design_pattern_for_c  V 1.00
event_threadpool.h File Reference

This is API as ThreadPool design petten by using libevent. More...

Include dependency graph for event_threadpool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

API for EventTPoolManager instance
EventTPoolManager event_tpool_manager_new (int thread_num, int is_threadsafe, const char *plugin_path)
 new EventTPoolManager More...
 
void event_tpool_manager_free (EventTPoolManager this)
 destructor of EventTPoolManager More...
 
size_t event_tpool_manager_get_threadnum (EventTPoolManager this)
 get size of thread More...
 
API for EventThreadPool
event_tpool_add_result_t event_tpool_add (EventTPoolManager this, EventSubscriber subscriber, void *arg)
 add EventSubscriber to threadpool More...
 
event_tpool_add_result_t event_tpool_add_thread (EventTPoolManager this, int threadid, EventSubscriber subscriber, void *arg)
 add EventSubscriber to threadpool, if you want to choose thead, please use it. More...
 
event_tpool_add_result_t event_tpool_update (EventTPoolManager this, EventTPoolThreadInfo event_handle, EventSubscriber subscriber, void *arg)
 update EventSubscriber to threadpool. More...
 
void event_tpool_del (EventTPoolManager this, int fd)
 delete EventSubscriber to threadapool. More...
 
void event_tpool_atfork_child (EventTPoolManager this)
 Update member at fork, please call this API on child process if you use fork. More...
 
void event_tpool_set_stack_size (size_t stack_size)
 Set thread stack size. More...
 

Detailed Description

This is API as ThreadPool design petten by using libevent.

Definition in file event_threadpool.h.

Function Documentation

◆ event_tpool_add()

event_tpool_add_result_t event_tpool_add ( EventTPoolManager  this,
EventSubscriber  subscriber,
void *  arg 
)

add EventSubscriber to threadpool

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
[in]subscriberEventSubscriber
[in]argargument for event_callback
Return values
resultthread number (0-thread_num-1) which subscriber added, event_handle is used for update
result<0 error (no resource, or if a same fd's subscriber was already registred)
Note
if there already exist same fd's subscriber, it occur error

Definition at line 343 of file event_tpool_manager.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event_tpool_add_thread()

event_tpool_add_result_t event_tpool_add_thread ( EventTPoolManager  this,
int  threadid,
EventSubscriber  subscriber,
void *  arg 
)

add EventSubscriber to threadpool, if you want to choose thead, please use it.

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
[in]threadidthread id (0-thread_num-1)
[in]subscriberEventSubscriber
[in]argargument for event_callback
Return values
resultthread number (0-thread_num-1) which subscriber added, event_handle is used for update
result<0 error (no resource, or if a same fd's subscriber was already registred)
Note
if there already exist same fd's subscriber, it occur error

Definition at line 373 of file event_tpool_manager.c.

Here is the call graph for this function:

◆ event_tpool_atfork_child()

void event_tpool_atfork_child ( EventTPoolManager  this)

Update member at fork, please call this API on child process if you use fork.

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
Note
Please care "The child process is created with a single thread--the one that called fork()." at the child process, all of pooled threads don't copy.

Definition at line 453 of file event_tpool_manager.c.

Here is the call graph for this function:

◆ event_tpool_del()

void event_tpool_del ( EventTPoolManager  this,
int  fd 
)

delete EventSubscriber to threadapool.

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
[in]fdremoved fd (related to subscriber)
Returns
none
Note
this API doesn't close fd, please close ownself.

Definition at line 430 of file event_tpool_manager.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event_tpool_manager_free()

void event_tpool_manager_free ( EventTPoolManager  this)

destructor of EventTPoolManager

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
Note
when call it, stop all threads.

Definition at line 319 of file event_tpool_manager.c.

Here is the call graph for this function:

◆ event_tpool_manager_get_threadnum()

size_t event_tpool_manager_get_threadnum ( EventTPoolManager  this)

get size of thread

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
Return values
sizeof thread
-1error

Definition at line 331 of file event_tpool_manager.c.

◆ event_tpool_manager_new()

EventTPoolManager event_tpool_manager_new ( int  thread_num,
int  is_threadsafe,
const char *  plugin_path 
)

new EventTPoolManager

Parameters
[in]thread_numsize of thread. If this is negative value, this library set thread CPU number * 2
[in]is_threadsafeif you use this instance in multi thread, please set 1.
[in]plugin_pathif you want to choose plugin. Default : choose higher priority plugin from prefix
Return values
!=NULLthis class handle
NULLerror
Note
when call it, start thread which has event_base struct. Those threads pool event fd, and call event function.

Definition at line 278 of file event_tpool_manager.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event_tpool_set_stack_size()

void event_tpool_set_stack_size ( size_t  stack_size)

Set thread stack size.

Default is 256 KByte.

Parameters
[in]stack_sizestack size.
Note
Please call it before calling event_tpool_manager_new.

Definition at line 462 of file event_tpool_manager.c.

Here is the call graph for this function:

◆ event_tpool_update()

event_tpool_add_result_t event_tpool_update ( EventTPoolManager  this,
EventTPoolThreadInfo  event_handle,
EventSubscriber  subscriber,
void *  arg 
)

update EventSubscriber to threadpool.

if you want to choose thead, please use it.

Parameters
[in]thisEventTPoolManager instance returned at event_tpool_new.
[in]event_handlehandler of event returned at event_tpool_add/event_tpool_add_thread
[in]subscriberEventSubscriber
[in]argargument for event_callback
Return values
resultthread number (0-thread_num-1) which subscriber added
result<0 error (no resource, or if a same fd's subscriber was already registred)
Note
if there already exist same fd's subscriber, it will override
this API doesn't remove other thread's same fd setting.
handle will update

Definition at line 403 of file event_tpool_manager.c.

Here is the call graph for this function: