acl  3.5.3.0
fiber_base.h 文件参考
#include <stdarg.h>
#include "fiber_define.h"
+ fiber_base.h 的引用(Include)关系图:
+ 此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

宏定义

#define FIBER_EVENT_KERNEL   0 /* epoll/kqueue/iocp */
 
#define FIBER_EVENT_POLL   1 /* poll */
 
#define FIBER_EVENT_SELECT   2 /* select */
 
#define FIBER_EVENT_WMSG   3 /* win message */
 

类型定义

typedef ACL_FIBER *(* FIBER_ALLOC_FN) (void(*) (ACL_FIBER *), size_t))
 
typedef ACL_FIBER *(* FIBER_ORIGIN_FN) (void))
 
typedef void(* FIBER_MSG_PRE_WRITE_FN) (void *ctx, const char *fmt, va_list ap)
 
typedef void(* FIBER_MSG_WRITE_FN) (void *ctx, const char *fmt, va_list ap)
 

函数

FIBER_API void acl_fiber_register (FIBER_ALLOC_FN alloc_fn, FIBER_ORIGIN_FN origin_fn)
 
FIBER_API ACL_FIBERacl_fiber_alloc (size_t size, void **pptr)
 
FIBER_API void acl_fiber_hook_api (int onoff)
 
FIBER_API ACL_FIBERacl_fiber_create (void(*fn)(ACL_FIBER *, void *), void *arg, size_t size)
 
FIBER_API unsigned acl_fiber_ndead (void)
 
FIBER_API unsigned acl_fiber_number (void)
 
FIBER_API void acl_fiber_check_timer (size_t max)
 
FIBER_API ACL_FIBERacl_fiber_running (void)
 
FIBER_API unsigned int acl_fiber_id (const ACL_FIBER *fiber)
 
FIBER_API unsigned int acl_fiber_self (void)
 
FIBER_API void acl_fiber_set_errno (ACL_FIBER *fiber, int errnum)
 
FIBER_API int acl_fiber_errno (ACL_FIBER *fiber)
 
FIBER_API void acl_fiber_keep_errno (ACL_FIBER *fiber, int yesno)
 
FIBER_API int acl_fiber_status (const ACL_FIBER *fiber)
 
FIBER_API void acl_fiber_kill (ACL_FIBER *fiber)
 
FIBER_API int acl_fiber_killed (ACL_FIBER *fiber)
 
FIBER_API int acl_fiber_signaled (ACL_FIBER *fiber)
 
FIBER_API int acl_fiber_closed (ACL_FIBER *fiber)
 
FIBER_API int acl_fiber_canceled (ACL_FIBER *fiber)
 
FIBER_API void acl_fiber_signal (ACL_FIBER *fiber, int signum)
 
FIBER_API int acl_fiber_signum (ACL_FIBER *fiber)
 
FIBER_API int acl_fiber_yield (void)
 
FIBER_API void acl_fiber_ready (ACL_FIBER *fiber)
 
FIBER_API void acl_fiber_switch (void)
 
FIBER_API void acl_fiber_schedule_init (int on)
 
FIBER_API void acl_fiber_schedule (void)
 
FIBER_API void acl_fiber_schedule_with (int event_mode)
 
FIBER_API void acl_fiber_schedule_set_event (int event_mode)
 
FIBER_API int acl_fiber_scheduled (void)
 
FIBER_API void acl_fiber_schedule_stop (void)
 
FIBER_API unsigned int acl_fiber_delay (unsigned int milliseconds)
 
FIBER_API unsigned int acl_fiber_sleep (unsigned int seconds)
 
FIBER_API ACL_FIBERacl_fiber_create_timer (unsigned int milliseconds, size_t size, void(*fn)(ACL_FIBER *, void *), void *ctx)
 
FIBER_API void acl_fiber_reset_timer (ACL_FIBER *timer, unsigned int milliseconds)
 
FIBER_API void acl_fiber_set_dns (const char *ip, int port)
 
FIBER_API int acl_fiber_set_specific (int *key, void *ctx, void(*free_fn)(void *))
 
FIBER_API void * acl_fiber_get_specific (int key)
 
FIBER_API void acl_fiber_msg_register (FIBER_MSG_WRITE_FN write_fn, void *ctx)
 
FIBER_API void acl_fiber_msg_unregister (void)
 
FIBER_API void acl_fiber_msg_pre_write (FIBER_MSG_PRE_WRITE_FN pre_write, void *ctx)
 
FIBER_API void acl_fiber_msg_stdout_enable (int onoff)
 
FIBER_API int acl_fiber_last_error (void)
 
FIBER_API const char * acl_fiber_last_serror (void)
 
FIBER_API const char * acl_fiber_strerror (int errnum, char *buf, size_t size)
 
FIBER_API void acl_fiber_set_error (int errnum)
 
FIBER_API int acl_fiber_set_fdlimit (int limit)
 
FIBER_API int acl_fiber_gettimeofday (struct timeval *tv, struct timezone *tz)
 
FIBER_API void acl_fiber_memstat (void)
 

宏定义说明

◆ FIBER_EVENT_KERNEL

#define FIBER_EVENT_KERNEL   0 /* epoll/kqueue/iocp */

start the fiber schedule process with the specified event type, the default event type is FIBER_EVENT_KERNEL. acl_fiber_schedule using the default event type. FIBER_EVENT_KERNEL is diffrent for diffrent OS platform: Linux: epoll; BSD: kqueue; Windows: iocp.

参数
event_mode{int} the event type, defined as FIBER_EVENT_XXX

在文件 fiber_base.h189 行定义.

◆ FIBER_EVENT_POLL

#define FIBER_EVENT_POLL   1 /* poll */

在文件 fiber_base.h190 行定义.

◆ FIBER_EVENT_SELECT

#define FIBER_EVENT_SELECT   2 /* select */

在文件 fiber_base.h191 行定义.

◆ FIBER_EVENT_WMSG

#define FIBER_EVENT_WMSG   3 /* win message */

在文件 fiber_base.h192 行定义.

类型定义说明

◆ FIBER_ALLOC_FN

typedef ACL_FIBER*(* FIBER_ALLOC_FN) (void(*)(ACL_FIBER *), size_t))

在文件 fiber_base.h11 行定义.

◆ FIBER_MSG_PRE_WRITE_FN

typedef void(* FIBER_MSG_PRE_WRITE_FN) (void *ctx, const char *fmt, va_list ap)

log function type used in fiber logging process, should be set by the function acl_fiber_msg_pre_write

参数
ctx{void*} the user's context
fmt{const char*} format of parameters
ap{va_list} list of parameters

在文件 fiber_base.h283 行定义.

◆ FIBER_MSG_WRITE_FN

typedef void(* FIBER_MSG_WRITE_FN) (void *ctx, const char *fmt, va_list ap)

log function type used in fiber logging process, should be set by the function acl_fiber_msg_register. This can be used by user for get the logging information of fiber

参数
ctx{void*} the user's context
fmt{const char*} format of parameters
ap{va_list} list of parameters

在文件 fiber_base.h293 行定义.

◆ FIBER_ORIGIN_FN

typedef ACL_FIBER*(* FIBER_ORIGIN_FN) (void))

在文件 fiber_base.h12 行定义.

函数说明

◆ acl_fiber_alloc()

FIBER_API ACL_FIBER* acl_fiber_alloc ( size_t  size,
void **  pptr 
)

◆ acl_fiber_canceled()

FIBER_API int acl_fiber_canceled ( ACL_FIBER fiber)

check if the specified fiber has been canceled

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running
返回
{int} non zero returned if been canceled

◆ acl_fiber_check_timer()

FIBER_API void acl_fiber_check_timer ( size_t  max)

create one fiber in background for freeing the dead fibers, specify the maximum fibers in every recyling process

参数
max{size_t} the maximum fibers to freed in every recyling process

◆ acl_fiber_closed()

FIBER_API int acl_fiber_closed ( ACL_FIBER fiber)

check if the specified fiber's socket has been closed by another fiber

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running
返回
{int} non zero returned if been closed

◆ acl_fiber_create()

FIBER_API ACL_FIBER* acl_fiber_create ( void(*)(ACL_FIBER *, void *)  fn,
void *  arg,
size_t  size 
)

create and start one fiber

参数
fn{void (*)(ACL_FIBER*, void*)} the callback of fiber running
arg{void*} the second parameter of the callback fn
size{size_t} the virual memory size of the fiber created
返回
{ACL_FIBER*}

◆ acl_fiber_create_timer()

FIBER_API ACL_FIBER* acl_fiber_create_timer ( unsigned int  milliseconds,
size_t  size,
void(*)(ACL_FIBER *, void *)  fn,
void *  ctx 
)

create one fiber timer

参数
milliseconds{unsigned int} the timer wakeup milliseconds
size{size_t} the virtual memory of the created fiber
fn{void (*)(ACL_FIBER*, void*)} the callback when fiber wakeup
ctx{void*} the second parameter of the callback fn
返回
{ACL_FIBER*} the new created fiber returned

◆ acl_fiber_delay()

FIBER_API unsigned int acl_fiber_delay ( unsigned int  milliseconds)

let the current fiber sleep for a while

参数
milliseconds{unsigned int} the milliseconds to sleep
返回
{unsigned int} the rest milliseconds returned after wakeup

◆ acl_fiber_errno()

FIBER_API int acl_fiber_errno ( ACL_FIBER fiber)

get the error number of assosiated fiber

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running
返回
{int} get the error number of assosiated fiber

◆ acl_fiber_get_specific()

FIBER_API void* acl_fiber_get_specific ( int  key)

get the current fiber's local object assosiated with the specified indexed key

参数
key{int} the integer value returned by acl_fiber_set_specific @retur {void*} NULL returned if no fiber local object with the specified key

◆ acl_fiber_gettimeofday()

FIBER_API int acl_fiber_gettimeofday ( struct timeval *  tv,
struct timezone *  tz 
)

◆ acl_fiber_hook_api()

FIBER_API void acl_fiber_hook_api ( int  onoff)

set flag if the system API should be hooked, default value is 1 internal

参数
onoff{int} if need to hook the system API

◆ acl_fiber_id()

FIBER_API unsigned int acl_fiber_id ( const ACL_FIBER fiber)

get the fiber ID of the specified fiber

参数
fiber{const ACL_FIBER*} the specified fiber object
返回
{unsigned int} return the fiber ID

◆ acl_fiber_keep_errno()

FIBER_API void acl_fiber_keep_errno ( ACL_FIBER fiber,
int  yesno 
)
弃用:
参数
fiber{ACL_FIBER*}
yesno{int}

◆ acl_fiber_kill()

FIBER_API void acl_fiber_kill ( ACL_FIBER fiber)

kill the suspended fiber and notify it to exit

参数
fiber{const ACL_FIBER*} the specified fiber, NOT NULL

◆ acl_fiber_killed()

FIBER_API int acl_fiber_killed ( ACL_FIBER fiber)

check if the specified fiber has been killed

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running
返回
{int} non zero returned if been killed

◆ acl_fiber_last_error()

FIBER_API int acl_fiber_last_error ( void  )

get the system error number of last system API calling

返回
{int} error number

◆ acl_fiber_last_serror()

FIBER_API const char* acl_fiber_last_serror ( void  )

get the error information of last system API calling

返回
{const char*}

◆ acl_fiber_memstat()

FIBER_API void acl_fiber_memstat ( void  )

◆ acl_fiber_msg_pre_write()

FIBER_API void acl_fiber_msg_pre_write ( FIBER_MSG_PRE_WRITE_FN  pre_write,
void *  ctx 
)

register the user's callback

参数
pre_write{MSG_PRE_WRITE_FN}
ctx{void*}

◆ acl_fiber_msg_register()

FIBER_API void acl_fiber_msg_register ( FIBER_MSG_WRITE_FN  write_fn,
void *  ctx 
)

set the user's log saving function when process started

参数
write_fn{MSG_WRITE_FN} log function defined by the user
ctx{void*} parameter will be transfered to write_fn

◆ acl_fiber_msg_stdout_enable()

FIBER_API void acl_fiber_msg_stdout_enable ( int  onoff)

if showing the fiber schedule process's log to stdout

参数
onoff{int} log will be showed to stdout if onoff isn't 0

◆ acl_fiber_msg_unregister()

FIBER_API void acl_fiber_msg_unregister ( void  )

cleanup the registered log callback by acl_fiber_msg_register

◆ acl_fiber_ndead()

FIBER_API unsigned acl_fiber_ndead ( void  )

get the fibers count in deading status

返回
{unsigned}

◆ acl_fiber_number()

FIBER_API unsigned acl_fiber_number ( void  )

get the fibers count in aliving status

返回
{unsigned}

◆ acl_fiber_ready()

FIBER_API void acl_fiber_ready ( ACL_FIBER fiber)

add the suspended fiber into resuming queue

参数
fiber{ACL_FIBER*} the fiber, NOT NULL

◆ acl_fiber_register()

FIBER_API void acl_fiber_register ( FIBER_ALLOC_FN  alloc_fn,
FIBER_ORIGIN_FN  origin_fn 
)

◆ acl_fiber_reset_timer()

FIBER_API void acl_fiber_reset_timer ( ACL_FIBER timer,
unsigned int  milliseconds 
)

reset the timer milliseconds time before the timer fiber wakeup

参数
timer{ACL_FIBER*} the fiber created by acl_fiber_create_timer
milliseconds{unsigned int} the new timer wakeup milliseconds

◆ acl_fiber_running()

FIBER_API ACL_FIBER* acl_fiber_running ( void  )

get the current running fiber @retur {ACL_FIBER*} if no running fiber NULL will be returned

◆ acl_fiber_schedule()

FIBER_API void acl_fiber_schedule ( void  )

start the fiber schedule process, the fibers in the ready quque will be started in sequence.

◆ acl_fiber_schedule_init()

FIBER_API void acl_fiber_schedule_init ( int  on)

set the fiber schedule process with automatically, in this way, when one fiber was created, the schedule process will start automatically, but only the first fiber was started, so you can create the other fibers in this fiber. The default schedule mode is non-automatically, you should call the acl_fiber_schedule or acl_fiber_schedule_with explicit

◆ acl_fiber_schedule_set_event()

FIBER_API void acl_fiber_schedule_set_event ( int  event_mode)

set the event type, the default type is FIBER_EVENT_KERNEL, this function must be called before acl_fiber_schedule.

参数
event_mode{int} the event type, defined as FIBER_EVENT_XXX

◆ acl_fiber_schedule_stop()

FIBER_API void acl_fiber_schedule_stop ( void  )

stop the fiber schedule process, all fibers will be stopped

◆ acl_fiber_schedule_with()

FIBER_API void acl_fiber_schedule_with ( int  event_mode)

◆ acl_fiber_scheduled()

FIBER_API int acl_fiber_scheduled ( void  )

check if the current thread is in fiber schedule status

返回
{int} non zero returned if in fiber schedule status

◆ acl_fiber_self()

FIBER_API unsigned int acl_fiber_self ( void  )

get the current running fiber's ID

返回
{unsigned int} the current fiber's ID

◆ acl_fiber_set_dns()

FIBER_API void acl_fiber_set_dns ( const char *  ip,
int  port 
)

set the DNS service addr

参数
ip{const char*} ip of the DNS service
port{int} port of the DNS service

◆ acl_fiber_set_errno()

FIBER_API void acl_fiber_set_errno ( ACL_FIBER fiber,
int  errnum 
)

set the error number to the specified fiber object

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running fiber will be used
errnum{int} the error number

◆ acl_fiber_set_error()

FIBER_API void acl_fiber_set_error ( int  errnum)

set the system error number

参数
errnum{int} the error number

◆ acl_fiber_set_fdlimit()

FIBER_API int acl_fiber_set_fdlimit ( int  limit)

set the fd limit for the current process

参数
limit{int} the fd limit to be set
返回
{int} the real fd limit will be returned

◆ acl_fiber_set_specific()

FIBER_API int acl_fiber_set_specific ( int *  key,
void *  ctx,
void(*)(void *)  free_fn 
)

set the current fiber's local object

参数
key{int*} the addr of indexed key, its initial value should <= 0, and one integer which > 0 will be set for it; the fiber local object will be assosiated with the indexed key.
ctx{void *} the fiber local object
free_fn{void (*)(void*)} the callback will be called before the current fiber exiting
返回
{int} the integer value(>0) of indexed key returned, value less than 0 will be returned if no running fiber

◆ acl_fiber_signal()

FIBER_API void acl_fiber_signal ( ACL_FIBER fiber,
int  signum 
)

wakeup the suspended fiber with the assosiated signal number

参数
fiber{const ACL_FIBER*} the specified fiber, NOT NULL
signum{int} SIGINT, SIGKILL, SIGTERM ... refer to bits/signum.h

◆ acl_fiber_signaled()

FIBER_API int acl_fiber_signaled ( ACL_FIBER fiber)

check if the specified fiber has been signaled

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running
返回
{int} non zero returned if been signed

◆ acl_fiber_signum()

FIBER_API int acl_fiber_signum ( ACL_FIBER fiber)

get the signal number got from other fiber

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running @retur {int} the signal number got

◆ acl_fiber_sleep()

FIBER_API unsigned int acl_fiber_sleep ( unsigned int  seconds)

let the current fiber sleep for a while

参数
seconds{unsigned int} the seconds to sleep
返回
{unsigned int} the rest seconds returned after wakeup

◆ acl_fiber_status()

FIBER_API int acl_fiber_status ( const ACL_FIBER fiber)

get the assosiated fiber's status

参数
fiber{ACL_FIBER*} the specified fiber, if NULL the current running
返回
{int}

◆ acl_fiber_strerror()

FIBER_API const char* acl_fiber_strerror ( int  errnum,
char *  buf,
size_t  size 
)

convert errno to string

参数
errnum{int}
buf{char*} hold the result
size{size_t} buf's size @retur {const char*} the addr of buf

◆ acl_fiber_switch()

FIBER_API void acl_fiber_switch ( void  )

suspend the current fiber and switch to run the next ready fiber

◆ acl_fiber_yield()

FIBER_API int acl_fiber_yield ( void  )

suspend the current running fiber

返回
{int}