design_pattern_for_c  V 1.00
event_tpool_manager.c File Reference

This is API implement for EventTPoolManager class. More...

#include <elf.h>
#include <stdio.h>
#include <sched.h>
#include "config.h"
#include "event_threadpool.h"
#include "event_thread.h"
#include "dp_util.h"
Include dependency graph for event_tpool_manager.c:

Go to the source code of this file.

Data Structures

struct  event_tpool_thread_info_t
 
union  event_tpool_thread_info_t::data_fds_u
 
struct  event_tpool_manager_t
 EventTPoolManager class instance definition. More...
 

Macros

#define _GNU_SOURCE
 
#define EV_TPOLL_FD_START   (3)
 
#define EV_TPOLL_FDSU64PLACE(fd)   (((fd)-EV_TPOLL_FD_START)/EV_TPOLL_U64_BITSIZE)
 
#define EV_TPOLL_FDINDEX(fd, place)   ((fd) - ((place)*EV_TPOLL_USABLE_BITSIZE) - EV_TPOLL_FD_START)
 
#define EV_TPOLL_FDINDEX_U8(fd, place, place_u8)   (EV_TPOLL_FDINDEX(fd,place) - ((place_u8) * EV_TPOLL_U8_BITSIZE))
 
#define EV_TPOLL_FD(place, place_u8, index)   (index + ((place)*EV_TPOLL_USABLE_BITSIZE) + ((place_u8) * EV_TPOLL_U8_BITSIZE) + EV_TPOLL_FD_START)
 

Functions

static int event_tpoll_get_far_right_bit_index (uint8_t data)
 
static void event_tpool_free_fddata (EventTPoolThreadInfo this, int place)
 
static void event_tpool_thread_delete_thread (EventTPoolThreadInfo this, int fd)
 delete thread More...
 
thread information list API definition.
static void event_tpool_thread_info_start_thread (EventTPoolThreadInfo instance)
 start thread More...
 
static void event_tpool_thread_info_stop_thread (EventTPoolThreadInfo this)
 stop thread More...
 
static int event_tpool_thread_has_fd (EventTPoolThreadInfo this, int fd)
 search current setting More...
 
EventTPoolThreadInfo list API and EventTPoolFDData list API definition.
static EventTPoolThreadInfo event_tpool_thread_info_new (size_t thread_size, const char *plugin_path)
 new thread info More...
 
static void event_tpool_thread_info_free (EventTPoolThreadInfo this, size_t thread_size)
 free thread info More...
 
static void event_tpool_free_fddata_list (EventTPoolThreadInfo this)
 free fddata More...
 
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...
 
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...
 

thread information list definition.

#define EV_TPOLL_U64_BITSIZE   (64)
 thread instance and fd list More...
 
#define EV_TPOLL_U8_BITSIZE   (8)
 
#define EV_TPOLL_USABLE_BITSIZE   (64)
 
typedef struct event_tpool_thread_info_t event_tpool_thread_info_t
 
typedef union data_fds_u data_fds_u
 
static void event_tpool_thread_set_fds (EventTPoolThreadInfo this, int fd)
 
static void event_tpool_thread_unset_fds (EventTPoolThreadInfo this, int fd)
 
static int event_tpool_thread_is_set_fds (EventTPoolThreadInfo this, int fd)
 
static void event_tpool_thread_insert_fddata (EventTPoolThreadInfo this, int fd)
 

for EventTPoolManager private API definition .

#define EVT_TPOOL_MNG_LOCK(this)   DPUTIL_LOCK(this->lock);
 
#define EVT_TPOOL_MNG_UNLOCK   DPUTIL_UNLOCK;
 
static void event_tpool_manager_free_without_lock (EventTPoolManager this)
 
static int event_tpool_manager_get_default_thrednum (void)
 
static int event_tpool_manager_search_insert_thread (EventTPoolManager this, int fd, int *has_fd)
 search insert place, to use event_tpool_thread_insert_thread More...
 

Detailed Description

This is API implement for EventTPoolManager class.

Definition in file event_tpool_manager.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 5 of file event_tpool_manager.c.

◆ EV_TPOLL_FD

#define EV_TPOLL_FD (   place,
  place_u8,
  index 
)    (index + ((place)*EV_TPOLL_USABLE_BITSIZE) + ((place_u8) * EV_TPOLL_U8_BITSIZE) + EV_TPOLL_FD_START)

Definition at line 102 of file event_tpool_manager.c.

◆ EV_TPOLL_FD_START

#define EV_TPOLL_FD_START   (3)

Definition at line 97 of file event_tpool_manager.c.

◆ EV_TPOLL_FDINDEX

#define EV_TPOLL_FDINDEX (   fd,
  place 
)    ((fd) - ((place)*EV_TPOLL_USABLE_BITSIZE) - EV_TPOLL_FD_START)

Definition at line 100 of file event_tpool_manager.c.

◆ EV_TPOLL_FDINDEX_U8

#define EV_TPOLL_FDINDEX_U8 (   fd,
  place,
  place_u8 
)    (EV_TPOLL_FDINDEX(fd,place) - ((place_u8) * EV_TPOLL_U8_BITSIZE))

Definition at line 101 of file event_tpool_manager.c.

◆ EV_TPOLL_FDSU64PLACE

#define EV_TPOLL_FDSU64PLACE (   fd)    (((fd)-EV_TPOLL_FD_START)/EV_TPOLL_U64_BITSIZE)

Definition at line 99 of file event_tpool_manager.c.

◆ EV_TPOLL_U64_BITSIZE

#define EV_TPOLL_U64_BITSIZE   (64)

thread instance and fd list

Definition at line 23 of file event_tpool_manager.c.

◆ EV_TPOLL_U8_BITSIZE

#define EV_TPOLL_U8_BITSIZE   (8)

Definition at line 24 of file event_tpool_manager.c.

◆ EV_TPOLL_USABLE_BITSIZE

#define EV_TPOLL_USABLE_BITSIZE   (64)

Definition at line 25 of file event_tpool_manager.c.

◆ EVT_TPOOL_MNG_LOCK

#define EVT_TPOOL_MNG_LOCK (   this)    DPUTIL_LOCK(this->lock);

Definition at line 77 of file event_tpool_manager.c.

◆ EVT_TPOOL_MNG_UNLOCK

#define EVT_TPOOL_MNG_UNLOCK   DPUTIL_UNLOCK;

Definition at line 78 of file event_tpool_manager.c.

Typedef Documentation

◆ data_fds_u

typedef union data_fds_u data_fds_u

Definition at line 36 of file event_tpool_manager.c.

◆ event_tpool_thread_info_t

Function Documentation

◆ event_tpoll_get_far_right_bit_index()

static int event_tpoll_get_far_right_bit_index ( uint8_t  data)
static

Definition at line 88 of file event_tpool_manager.c.

Here is the caller graph for this function:

◆ 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_free_fddata()

static void event_tpool_free_fddata ( EventTPoolThreadInfo  this,
int  place 
)
static

Definition at line 138 of file event_tpool_manager.c.

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

◆ event_tpool_free_fddata_list()

static void event_tpool_free_fddata_list ( EventTPoolThreadInfo  this)
static

free fddata

Definition at line 155 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_free_without_lock()

static void event_tpool_manager_free_without_lock ( EventTPoolManager  this)
static

Definition at line 237 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_get_default_thrednum()

static int event_tpool_manager_get_default_thrednum ( void  )
static

Definition at line 243 of file event_tpool_manager.c.

Here is the caller 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_manager_search_insert_thread()

static int event_tpool_manager_search_insert_thread ( EventTPoolManager  this,
int  fd,
int *  has_fd 
)
static

search insert place, to use event_tpool_thread_insert_thread

Definition at line 250 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_thread_delete_thread()

static void event_tpool_thread_delete_thread ( EventTPoolThreadInfo  this,
int  fd 
)
static

delete thread

Definition at line 177 of file event_tpool_manager.c.

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

◆ event_tpool_thread_has_fd()

static int event_tpool_thread_has_fd ( EventTPoolThreadInfo  this,
int  fd 
)
static

search current setting

Definition at line 134 of file event_tpool_manager.c.

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

◆ event_tpool_thread_info_free()

static void event_tpool_thread_info_free ( EventTPoolThreadInfo  this,
size_t  thread_size 
)
static

free thread info

Definition at line 227 of file event_tpool_manager.c.

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

◆ event_tpool_thread_info_new()

static EventTPoolThreadInfo event_tpool_thread_info_new ( size_t  thread_size,
const char *  plugin_path 
)
static

new thread info

Definition at line 185 of file event_tpool_manager.c.

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

◆ event_tpool_thread_info_start_thread()

static void event_tpool_thread_info_start_thread ( EventTPoolThreadInfo  instance)
static

start thread

Definition at line 164 of file event_tpool_manager.c.

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

◆ event_tpool_thread_info_stop_thread()

static void event_tpool_thread_info_stop_thread ( EventTPoolThreadInfo  this)
static

stop thread

Definition at line 169 of file event_tpool_manager.c.

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

◆ event_tpool_thread_insert_fddata()

static void event_tpool_thread_insert_fddata ( EventTPoolThreadInfo  this,
int  fd 
)
static

Definition at line 129 of file event_tpool_manager.c.

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

◆ event_tpool_thread_is_set_fds()

static int event_tpool_thread_is_set_fds ( EventTPoolThreadInfo  this,
int  fd 
)
static

Definition at line 119 of file event_tpool_manager.c.

Here is the caller graph for this function:

◆ event_tpool_thread_set_fds()

static void event_tpool_thread_set_fds ( EventTPoolThreadInfo  this,
int  fd 
)
static

Definition at line 104 of file event_tpool_manager.c.

Here is the caller graph for this function:

◆ event_tpool_thread_unset_fds()

static void event_tpool_thread_unset_fds ( EventTPoolThreadInfo  this,
int  fd 
)
static

Definition at line 111 of file event_tpool_manager.c.

Here is the caller 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: