1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_FIBER_H_INCLUDED_
8 #define _NXT_FIBER_H_INCLUDED_
9 
10 
11 typedef struct nxt_fiber_main_s   nxt_fiber_main_t;
12 typedef void (*nxt_fiber_start_t)(void *data);
13 
14 
15 typedef uint32_t            nxt_fid_t;
16 #define nxt_fiber_id(f)     (f)->fid;
17 
18 
19 typedef struct nxt_fiber_s  nxt_fiber_t;
20 
21 struct nxt_fiber_s {
22     jmp_buf                 jmp;
23     nxt_fid_t               fid;
24     nxt_fiber_start_t       start;
25     void                    *data;
26     char                    *stack;
27     size_t                  stack_size;
28     nxt_err_t               err;
29 
30     nxt_task_t              task;
31 
32     nxt_fiber_main_t        *main;
33     nxt_fiber_t             *next;
34 
35     nxt_timer_t             timer;
36 };
37 
38 
39 struct nxt_fiber_main_s {
40     nxt_fiber_t             fiber;
41     nxt_fiber_t             *idle;
42     nxt_event_engine_t      *engine;
43     size_t                  stack_size;
44     nxt_fid_t               fid;
45 };
46 
47 
48 nxt_fiber_main_t *nxt_fiber_main_create(nxt_event_engine_t *engine);
49 nxt_int_t nxt_fiber_create(nxt_fiber_start_t start, void *data, size_t stack);
50 void nxt_fiber_yield(nxt_task_t *task);
51 void nxt_fiber_sleep(nxt_task_t *task, nxt_msec_t timeout);
52 void nxt_fiber_wait(nxt_task_t *task);
53 void nxt_fiber_exit(nxt_task_t *task, nxt_fiber_t *next, void *data);
54 NXT_EXPORT nxt_fiber_t *nxt_fiber_self(nxt_thread_t *thr);
55 
56 
57 #endif /* _NXT_FIBER_H_INCLUDED_ */
58