design_pattern_for_c  V 1.00
event_thread.c File Reference

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

#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/eventfd.h>
#include <errno.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include "event_thread.h"
#include "tpool_event_if.h"
#include "dp_util.h"
#include "config.h"
Include dependency graph for event_thread.c:

Go to the source code of this file.

Data Structures

struct  event_thread_msg_body_add_t
 message definition for manage subscriber More...
 
struct  event_thread_msg_body_del_t
 
struct  event_thread_msg_t
 message struct definition More...
 
struct  event_thread_msg_info_t
 
struct  event_subscriber_data_t
 subscriber information define More...
 
struct  event_tpool_thread_t
 thread information More...
 

Macros

#define EVENT_THREAD_WAIT_TIMEOUT   (2)/*sec*/
 
#define EVENT_THREAD_STACKSIZE   (256 * 1024)/*suitable stack size*/
 

Functions

EventTPoolThread event_tpool_thread_new (size_t thread_size)
 create and thread instance More...
 
void event_tpool_thread_start (EventTPoolThread this)
 start thread More...
 
void event_tpool_thread_stop (EventTPoolThread this)
 stop thread More...
 
void event_tpool_thread_add (EventTPoolThread this, EventSubscriber subscriber, void *arg)
 add new subscriber More...
 
void event_tpool_thread_update (EventTPoolThread this, EventSubscriber subscriber, void *arg)
 update subscriber More...
 
void event_tpool_thread_del (EventTPoolThread this, int fd)
 delete subscriber More...
 
void event_thread_atfork_child (EventTPoolThread this)
 
void event_thread_set_stack_size (size_t stack_size)
 
int event_tpool_thread_load_plugin (const char *plugin_path)
 
int event_tpool_thread_unload_plugin (void)
 
API for EventSubscriberData.
static EventSubscriberData event_subscriber_data_new (EventTPoolThread this, EventSubscriber subscriber, void *arg)
 new instance More...
 
static void event_subscriber_data_free (EventTPoolThread this, EventSubscriberData data)
 free instance More...
 
static int event_subscriber_data_get_fd (EventSubscriberData this)
 get fd More...
 
private API for EventTPoolThread.
static int event_tpool_thread_set_event_base (EventTPoolThread this)
 set event_base More...
 
static void event_tpool_thread_remove_event_base (EventTPoolThread this)
 remove event_base More...
 
static EventSubscriberData event_tpool_thread_get_subscriber (EventTPoolThread this, int fd)
 get subscriber More...
 
static void * event_tpool_thread_main (void *arg)
 main thread More...
 
static void event_tpool_thread_free (EventTPoolThread this)
 free thread instance, please call stop before calling it More...
 

event_tpool_thread_t definition.

#define event_thread_pop(this)   (EventSubscriberData)dputil_list_pop((DPUtilList)(this))
 
#define event_thread_pull(this, data)   dputil_list_pull((DPUtilList)(this), (DPUtilListData)(data))
 
#define event_thread_push(this, data)   dputil_list_push((DPUtilList)(this), (DPUtilListData)(data))
 
typedef struct event_thread_msg_body_add_t event_thread_msg_body_add_t
 message definition for manage subscriber More...
 
typedef struct event_thread_msg_body_del_t event_thread_msg_body_del_t
 
typedef struct event_thread_msg_t event_thread_msg_t
 
typedef struct event_thread_msg_tEventThreadMsg
 
typedef struct event_thread_msg_info_t event_thread_msg_info_t
 
typedef struct event_subscriber_data_tEventSubscriberData
 subscriber information define More...
 
struct {
   void *   handle
 
   EventInstance(*   new )(void)
 
   EventHandler(*   add )(EventInstance this,
      EventSubscriber subscriber,
      void *arg)
 
   EventHandler(*   update )(EventInstance this,
      EventHandler handler,
      EventSubscriber subscriber,
      void *arg)
 
   void(*   del )(EventInstance this,
      EventHandler handler)
 
   int(*   getfd )(EventHandler handler)
 
   int(*   loop )(EventInstance this)
 
   void(*   loopbreak )(EventInstance this)
 
   void(*   exit )(EventInstance this)
 
   void(*   free )(EventInstance this)
 
event_if_instance_g
 interface definition More...
 
static size_t event_thread_stack_size_g = EVENT_THREAD_STACKSIZE
 thread stack size, user can change it by using event_tpool_set_stack_size More...
 
static void event_thread_set_func (void *handle, const char *func_name, void **func)
 
static int event_tpool_thread_load_all_fun (void)
 
static const char * event_tpool_thread_get_defaullt_plugin (void)
 

API for message.

#define EVMSG_LOCK(this)   DPUTIL_LOCK(&this->msgdata.lock);
 
#define EVMSG_UNLOCK   DPUTIL_UNLOCK
 
static int event_thread_msg_send (EventTPoolThread this, EventThreadMsg msg)
 
static int event_thread_msg_send_without_lock (EventTPoolThread this, EventThreadMsg msg)
 
static void event_thread_msg_send_subscribe (EventTPoolThread this, EventSubscriber subscriber, void *arg, int type)
 
static void event_thread_msg_send_add (EventTPoolThread this, EventSubscriber subscriber, void *arg)
 
static void event_thread_msg_send_update (EventTPoolThread this, EventSubscriber subscriber, void *arg)
 
static void event_thread_msg_send_del (EventTPoolThread this, int fd)
 
static int event_thread_msg_send_stop (EventTPoolThread this)
 

API for EventTPoolThread msg callback

typedef void(* event_tpool_thread_msg_cb) (EventTPoolThread this, event_thread_msg_t *msg)
 
static event_tpool_thread_msg_cb event_tpool_thread_msg_cb_table []
 callback table More...
 
static void event_tpool_thread_msg_cb_add (EventTPoolThread this, event_thread_msg_t *msg)
 for add More...
 
static void event_tpool_thread_msg_cb_update (EventTPoolThread this, event_thread_msg_t *msg)
 for update More...
 
static void event_tpool_thread_msg_cb_del (EventTPoolThread this, event_thread_msg_t *msg)
 for del More...
 
static void event_tpool_thread_msg_cb_stop (EventTPoolThread this, event_thread_msg_t *msg)
 for stop More...
 
static void event_tpool_thread_msg_cb_call (EventTPoolThread this, event_thread_msg_t *msg)
 
static void event_tpool_thread_call_msgs (EventTPoolThread this, eventfd_t cnt)
 main messages caller More...
 
static void event_tpool_thread_cb (int, int, void *)
 callback main More...
 

Detailed Description

This is API implement for EventThread class.

Definition in file event_thread.c.

Macro Definition Documentation

◆ event_thread_pop

#define event_thread_pop (   this)    (EventSubscriberData)dputil_list_pop((DPUtilList)(this))

Definition at line 100 of file event_thread.c.

◆ event_thread_pull

#define event_thread_pull (   this,
  data 
)    dputil_list_pull((DPUtilList)(this), (DPUtilListData)(data))

Definition at line 101 of file event_thread.c.

◆ event_thread_push

#define event_thread_push (   this,
  data 
)    dputil_list_push((DPUtilList)(this), (DPUtilListData)(data))

Definition at line 102 of file event_thread.c.

◆ EVENT_THREAD_STACKSIZE

#define EVENT_THREAD_STACKSIZE   (256 * 1024)/*suitable stack size*/

Definition at line 21 of file event_thread.c.

◆ EVENT_THREAD_WAIT_TIMEOUT

#define EVENT_THREAD_WAIT_TIMEOUT   (2)/*sec*/

Definition at line 19 of file event_thread.c.

◆ EVMSG_LOCK

#define EVMSG_LOCK (   this)    DPUTIL_LOCK(&this->msgdata.lock);

Definition at line 122 of file event_thread.c.

◆ EVMSG_UNLOCK

#define EVMSG_UNLOCK   DPUTIL_UNLOCK

Definition at line 123 of file event_thread.c.

Typedef Documentation

◆ event_thread_msg_body_add_t

message definition for manage subscriber

◆ event_thread_msg_body_del_t

◆ event_thread_msg_info_t

◆ event_thread_msg_t

Definition at line 61 of file event_thread.c.

◆ event_tpool_thread_msg_cb

typedef void(* event_tpool_thread_msg_cb) (EventTPoolThread this, event_thread_msg_t *msg)

Definition at line 156 of file event_thread.c.

◆ EventSubscriberData

subscriber information define

Definition at line 92 of file event_thread.c.

◆ EventThreadMsg

Definition at line 61 of file event_thread.c.

Function Documentation

◆ event_subscriber_data_free()

static void event_subscriber_data_free ( EventTPoolThread  this,
EventSubscriberData  data 
)
static

free instance

Definition at line 314 of file event_thread.c.

Here is the caller graph for this function:

◆ event_subscriber_data_get_fd()

static int event_subscriber_data_get_fd ( EventSubscriberData  this)
static

get fd

Definition at line 321 of file event_thread.c.

Here is the caller graph for this function:

◆ event_subscriber_data_new()

static EventSubscriberData event_subscriber_data_new ( EventTPoolThread  this,
EventSubscriber  subscriber,
void *  arg 
)
static

new instance

Definition at line 293 of file event_thread.c.

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

◆ event_thread_atfork_child()

void event_thread_atfork_child ( EventTPoolThread  this)

Definition at line 612 of file event_thread.c.

Here is the caller graph for this function:

◆ event_thread_msg_send()

static int event_thread_msg_send ( EventTPoolThread  this,
EventThreadMsg  msg 
)
static

Definition at line 184 of file event_thread.c.

Here is the caller graph for this function:

◆ event_thread_msg_send_add()

static void event_thread_msg_send_add ( EventTPoolThread  this,
EventSubscriber  subscriber,
void *  arg 
)
static

Definition at line 230 of file event_thread.c.

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

◆ event_thread_msg_send_del()

static void event_thread_msg_send_del ( EventTPoolThread  this,
int  fd 
)
static

Definition at line 240 of file event_thread.c.

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

◆ event_thread_msg_send_stop()

static int event_thread_msg_send_stop ( EventTPoolThread  this)
static

Definition at line 263 of file event_thread.c.

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

◆ event_thread_msg_send_subscribe()

static void event_thread_msg_send_subscribe ( EventTPoolThread  this,
EventSubscriber  subscriber,
void *  arg,
int  type 
)
static

Definition at line 209 of file event_thread.c.

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

◆ event_thread_msg_send_update()

static void event_thread_msg_send_update ( EventTPoolThread  this,
EventSubscriber  subscriber,
void *  arg 
)
static

Definition at line 236 of file event_thread.c.

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

◆ event_thread_msg_send_without_lock()

static int event_thread_msg_send_without_lock ( EventTPoolThread  this,
EventThreadMsg  msg 
)
static

Definition at line 205 of file event_thread.c.

Here is the caller graph for this function:

◆ event_thread_set_func()

static void event_thread_set_func ( void *  handle,
const char *  func_name,
void **  func 
)
static

◆ event_thread_set_stack_size()

void event_thread_set_stack_size ( size_t  stack_size)

Definition at line 619 of file event_thread.c.

Here is the caller graph for this function:

◆ event_tpool_thread_add()

void event_tpool_thread_add ( EventTPoolThread  this,
EventSubscriber  subscriber,
void *  arg 
)

add new subscriber

Definition at line 601 of file event_thread.c.

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

◆ event_tpool_thread_call_msgs()

static void event_tpool_thread_call_msgs ( EventTPoolThread  this,
eventfd_t  cnt 
)
static

main messages caller

Definition at line 455 of file event_thread.c.

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

◆ event_tpool_thread_cb()

static void event_tpool_thread_cb ( int  fd,
int  flag,
void *  arg 
)
static

callback main

Definition at line 469 of file event_thread.c.

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

◆ event_tpool_thread_del()

void event_tpool_thread_del ( EventTPoolThread  this,
int  fd 
)

delete subscriber

Definition at line 609 of file event_thread.c.

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

◆ event_tpool_thread_free()

static void event_tpool_thread_free ( EventTPoolThread  this)
static

free thread instance, please call stop before calling it

Definition at line 362 of file event_thread.c.

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

◆ event_tpool_thread_get_defaullt_plugin()

static const char * event_tpool_thread_get_defaullt_plugin ( void  )
static

Definition at line 481 of file event_thread.c.

Here is the caller graph for this function:

◆ event_tpool_thread_get_subscriber()

static EventSubscriberData event_tpool_thread_get_subscriber ( EventTPoolThread  this,
int  fd 
)
static

get subscriber

Definition at line 373 of file event_thread.c.

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

◆ event_tpool_thread_load_all_fun()

static int event_tpool_thread_load_all_fun ( void  )
static

Definition at line 501 of file event_thread.c.

Here is the caller graph for this function:

◆ event_tpool_thread_load_plugin()

int event_tpool_thread_load_plugin ( const char *  plugin_path)

Definition at line 623 of file event_thread.c.

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

◆ event_tpool_thread_main()

static void * event_tpool_thread_main ( void *  arg)
static

main thread

Definition at line 385 of file event_thread.c.

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

◆ event_tpool_thread_msg_cb_add()

static void event_tpool_thread_msg_cb_add ( EventTPoolThread  this,
event_thread_msg_t msg 
)
static

for add

Definition at line 408 of file event_thread.c.

Here is the call graph for this function:

◆ event_tpool_thread_msg_cb_call()

static void event_tpool_thread_msg_cb_call ( EventTPoolThread  this,
event_thread_msg_t msg 
)
static

Definition at line 287 of file event_thread.c.

Here is the caller graph for this function:

◆ event_tpool_thread_msg_cb_del()

static void event_tpool_thread_msg_cb_del ( EventTPoolThread  this,
event_thread_msg_t msg 
)
static

for del

Definition at line 436 of file event_thread.c.

Here is the call graph for this function:

◆ event_tpool_thread_msg_cb_stop()

static void event_tpool_thread_msg_cb_stop ( EventTPoolThread  this,
event_thread_msg_t msg 
)
static

for stop

Definition at line 449 of file event_thread.c.

◆ event_tpool_thread_msg_cb_update()

static void event_tpool_thread_msg_cb_update ( EventTPoolThread  this,
event_thread_msg_t msg 
)
static

for update

Definition at line 422 of file event_thread.c.

Here is the call graph for this function:

◆ event_tpool_thread_new()

EventTPoolThread event_tpool_thread_new ( size_t  thread_size)

create and thread instance

Definition at line 537 of file event_thread.c.

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

◆ event_tpool_thread_remove_event_base()

static void event_tpool_thread_remove_event_base ( EventTPoolThread  this)
static

remove event_base

Definition at line 352 of file event_thread.c.

Here is the caller graph for this function:

◆ event_tpool_thread_set_event_base()

static int event_tpool_thread_set_event_base ( EventTPoolThread  this)
static

set event_base

Definition at line 330 of file event_thread.c.

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

◆ event_tpool_thread_start()

void event_tpool_thread_start ( EventTPoolThread  this)

start thread

Definition at line 569 of file event_thread.c.

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

◆ event_tpool_thread_stop()

void event_tpool_thread_stop ( EventTPoolThread  this)

stop thread

stop thread, and remove resource

Definition at line 585 of file event_thread.c.

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

◆ event_tpool_thread_unload_plugin()

int event_tpool_thread_unload_plugin ( void  )

Definition at line 649 of file event_thread.c.

Here is the caller graph for this function:

◆ event_tpool_thread_update()

void event_tpool_thread_update ( EventTPoolThread  this,
EventSubscriber  subscriber,
void *  arg 
)

update subscriber

Definition at line 604 of file event_thread.c.

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

Variable Documentation

◆ add

EventHandler(* add) (EventInstance this, EventSubscriber subscriber, void *arg)

Definition at line 32 of file event_thread.c.

◆ del

void(* del) (EventInstance this, EventHandler handler)

Definition at line 34 of file event_thread.c.

◆ event_if_instance_g

struct { ... } event_if_instance_g

interface definition

◆ event_thread_stack_size_g

size_t event_thread_stack_size_g = EVENT_THREAD_STACKSIZE
static

thread stack size, user can change it by using event_tpool_set_stack_size

Definition at line 47 of file event_thread.c.

◆ event_tpool_thread_msg_cb_table

event_tpool_thread_msg_cb event_tpool_thread_msg_cb_table[]
static
Initial value:
={
}
static void event_tpool_thread_msg_cb_add(EventTPoolThread this, event_thread_msg_t *msg)
for add
Definition: event_thread.c:408
static void event_tpool_thread_msg_cb_stop(EventTPoolThread this, event_thread_msg_t *msg)
for stop
Definition: event_thread.c:449
static void event_tpool_thread_msg_cb_del(EventTPoolThread this, event_thread_msg_t *msg)
for del
Definition: event_thread.c:436
static void event_tpool_thread_msg_cb_update(EventTPoolThread this, event_thread_msg_t *msg)
for update
Definition: event_thread.c:422

callback table

Definition at line 166 of file event_thread.c.

◆ exit

void(* exit) (EventInstance this)

Definition at line 38 of file event_thread.c.

◆ free

void(* free) (EventInstance this)

Definition at line 39 of file event_thread.c.

◆ getfd

int(* getfd) (EventHandler handler)

Definition at line 35 of file event_thread.c.

◆ handle

void* handle

Definition at line 30 of file event_thread.c.

◆ loop

int(* loop) (EventInstance this)

Definition at line 36 of file event_thread.c.

◆ loopbreak

void(* loopbreak) (EventInstance this)

Definition at line 37 of file event_thread.c.

◆ new

EventInstance(* new) (void)

Definition at line 31 of file event_thread.c.

◆ update

EventHandler(* update) (EventInstance this, EventHandler handler, EventSubscriber subscriber, void *arg)

Definition at line 33 of file event_thread.c.