Simple coroutine library integrated with IO event loop (libevent) / objects in plain C Snapshot
Classes | Typedefs | Functions
EVTHREAD

user mode thread attached to an event loop The thread owns one or more EVSOCKETS, it initially activated when the thread is created, and is futher activated when an IO event occurs on a EVSOCKET object owned by this thread. More...

Classes

struct  tagEVTHREAD

Typedefs

typedef void(* EVTHREAD_PROC )(struct tagEVTHREAD *thread, struct tagEVSOCKET *socket, void *user_ctx)
typedef struct tagEVTHREAD EVTHREAD

Functions

EVTHREADEVTHREAD_init (EVLOOP *loop, EVTHREAD_PROC thread_proc, void *user_ctx)
int EVTHREAD_start (EVTHREAD *thread, struct tagEVSOCKET *socket)
int EVTHREAD_delay (EVTHREAD *thread, struct timeval delay)

Detailed Description

user mode thread attached to an event loop The thread owns one or more EVSOCKETS, it initially activated when the thread is created, and is futher activated when an IO event occurs on a EVSOCKET object owned by this thread.


Typedef Documentation

typedef struct tagEVTHREAD EVTHREAD
typedef void(* EVTHREAD_PROC)(struct tagEVTHREAD *thread, struct tagEVSOCKET *socket, void *user_ctx)

Definition at line 69 of file evthread.h.


Function Documentation

int EVTHREAD_delay ( EVTHREAD thread,
struct timeval  delay 
)

Definition at line 110 of file evthread.c.

{
  event_set( &thread->timer_event, -1, 0, thread_timer_cb, (void *) thread );
  event_base_set( thread->loop->ev_base, &thread->timer_event );
  event_add( &thread->timer_event, &delay );
   
  CTHREAD_yield( 0, 0);
   
  event_del( &thread->timer_event );

 
  return 0;
}
EVTHREAD* EVTHREAD_init ( EVLOOP loop,
EVTHREAD_PROC  thread_proc,
void *  user_ctx 
)

Definition at line 79 of file evthread.c.

{
  EVTHREAD *thread;

  thread = (EVTHREAD *) malloc( sizeof( EVTHREAD ) );
  if (!thread) {
    return 0;
  }
  thread->loop = loop;
  thread->thread_proc = thread_proc;
  thread->user_context = user_ctx;

  thread->cthread = CTHREAD_init( loop->stacks, evthread_proc );
  if (!thread->cthread) {
    free(thread);
    return 0;
  }
  thread->socket = 0;

  DLIST_init( &thread->object_list );

  return thread;
}
int EVTHREAD_start ( EVTHREAD thread,
struct tagEVSOCKET socket 
)

Definition at line 103 of file evthread.c.

{
  thread->socket = socket;
  CTHREAD_start( thread->cthread, 0, "%p", thread );
  return 0;
}