31#ifndef XCOM_STANDALONE
49#ifdef TASK_EVENT_TRACE
50void add_base_event(
double when,
char const *
file,
int state);
51#define ADD_BASE_EVENT \
53 add_base_event(seconds(), __FILE__, __LINE__); \
54 add_event(EVENT_DUMP_PAD, string_arg(__func__)); \
57#define ADD_DBG(d, x) \
60 add_event(EVENT_DUMP_PAD, end_arg()); \
63#define ADD_EVENTS(x) ADD_DBG(D_BUG, x)
65#define ADD_T_EV(when, file, state, what)
66#define ADD_WAIT_EV(when, file, state, what, milli)
71#define ADD_T_EV(when, file, state, what)
72#define ADD_WAIT_EV(when, file, state, what, milli)
157 return (
char const *)arg.
val.
v;
228#define TASK_POOL_ELEMS 1000
275#define _ep ((struct env *)(stack->sp->ptr))
277#define TASK_ALLOC(pool, type) (task_allocate(pool, (unsigned int)sizeof(type)))
280#define TASK_DEBUG(x) \
281 if (stack->debug) { \
282 IFDBG(D_NONE, FN; STRLIT(x " task "); PTREXP((void *)stack); \
283 STRLIT(stack->name); NDBG(stack->sp->state, d)); \
295#define ON_STACK_TOP (stack->sp == stack->stack_top + 1)
301 if (ON_STACK_TOP && stack->terminate) goto task_cleanup
303#define TERMINATE goto task_cleanup
311 if (stack->sp->state) { \
312 add_event(EVENT_DUMP_PAD, string_arg("state")); \
313 add_event(EVENT_DUMP_PAD, int_arg(stack->sp->state)); \
314 } add_event(EVENT_DUMP_PAD, string_arg("TASK_BEGIN")); \
315 add_event(EVENT_DUMP_PAD, void_arg(stack));); \
316 TASK_DEBUG("TASK_BEGIN"); \
317 switch (stack->sp->state) { \
319 pushp(stack, TASK_ALLOC(stack, struct env)); \
329 if (stack->sp->state) { \
330 add_event(EVENT_DUMP_PAD, string_arg("state")); \
331 add_event(EVENT_DUMP_PAD, int_arg(stack->sp->state)); \
332 } add_event(EVENT_DUMP_PAD, string_arg("TASK_END")); \
333 add_event(EVENT_DUMP_PAD, void_arg(stack));); \
334 TASK_DEBUG("TASK_END"); \
335 stack->sp->state = 0; \
336 stack->where = (TaskAlign *)stack->sp->ptr; \
337 assert(stack->where); \
344#define TASK_RETURN(x) \
350#define TASK_DUMP_ERR \
351 if (errno || SOCK_ERRNO || task_errno) { \
352 IFDBG(D_NONE, FN; NDBG(errno, d); STREXP(strerror(errno)); \
353 NDBG(SOCK_ERRNO, d); STREXP(strerror(SOCK_ERRNO)); \
354 NDBG(task_errno, d); STREXP(strerror(task_errno))); \
362 IFDBG(D_NONE, FN; STRLIT("TASK_FAIL")); \
363 ADD_DBG(D_TASK, add_event(EVENT_DUMP_PAD, string_arg("task failed"))); \
372 TASK_DEBUG("TASK_YIELD"); \
373 stack->sp->state = __LINE__; \
376 TASK_DEBUG("RETURN FROM YIELD"); \
382#define TASK_DEACTIVATE \
384 TASK_DEBUG("TASK_DEACTIVATE"); \
385 task_deactivate(stack); \
392#define TASK_DELAY(t) \
394 TASK_DEBUG("TASK_DELAY"); \
395 task_delay_until(seconds() + t); \
402#define TASK_DELAY_UNTIL(t) \
404 TASK_DEBUG("TASK_DELAY_UNTIL"); \
405 task_delay_until(t); \
410#define TASK_WAIT(queue) \
412 TASK_DEBUG("TASK_WAIT"); \
413 task_wait(stack, queue); \
418#define TIMED_TASK_WAIT(queue, t) \
420 TASK_DEBUG("TIMED_TASK_WAIT"); \
421 task_delay_until(seconds() + (t)); \
422 task_wait(stack, queue); \
443#define CHANNEL_GET(channel, ptr, type) \
445 while (link_empty(&(channel)->data)) { \
446 TASK_WAIT(&(channel)->queue); \
448 *(ptr) = (type *)link_extract_first(&(channel)->data); \
449 IFDBG(D_TRANSPORT, FN; STRLIT("CHANNEL_GET "); PTREXP(*(ptr)); \
450 PTREXP(&((channel)->data))); \
453#define CHANNEL_PEEK(channel, ptr, type) \
455 while (link_empty(&(channel)->data)) { \
456 TASK_WAIT(&(channel)->queue); \
458 *(ptr) = (type *)link_first(&(channel)->data); \
461#define CHANNEL_GET_REVERSE(channel, ptr, type) \
463 while (link_empty(&(channel)->data)) { \
464 TASK_WAIT(&(channel)->queue); \
466 *(ptr) = (type *)link_extract_last(&(channel)->data); \
474#define TASK_CALL(funcall) \
476 reset_state(stack); \
477 TASK_DEBUG("BEFORE CALL"); \
480 stack->taskret = funcall; \
483 if (stack->taskret) TASK_YIELD; \
484 } while (stack->taskret); \
485 TASK_DEBUG("AFTER CALL"); \
490#define DECL_ENV struct env {
494#define ENV_INIT void init() {
496#define END_ENV_INIT }
502 [[maybe_unused]] struct env *ep
507#define LOCK_FD(fd, op) \
512 wait_io(stack, fd, op); \
519#define UNLOCK_FD(fd, op) unlock_fd(fd, stack, op)
521#ifdef TASK_EVENT_TRACE
522enum { EVENT_DUMP_PAD = 1, EVENT_DUMP_HEX = 2 };
529typedef struct task_event task_event;
532void add_task_event(
double when,
char const *
file,
int state,
char const *what);
533void add_wait_event(
double when,
char const *
file,
int state,
char const *what,
535void dump_task_events();
536void reset_task_events();
602extern xcom_proto
const
static char * add_event(const char *var, LEX_CSTRING event, const char *data, size_t data_length)
Definition: audit_null.cc:303
const char * p
Definition: ctype-mb.cc:1237
static int flag
Definition: hp_test1.cc:40
Header for compiler-dependent features.
static QUEUE queue
Definition: myisampack.cc:207
Definition: buf0block_hint.cc:30
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:496
struct result result
Definition: result.h:34
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:33
linkage queue
Definition: task.h:429
linkage data
Definition: task.h:428
Definition: node_connection.h:47
Definition: task_arg.h:42
unsigned long u_l
Definition: task_arg.h:48
float f
Definition: task_arg.h:50
double d
Definition: task_arg.h:51
void * v
Definition: task_arg.h:53
long l
Definition: task_arg.h:46
unsigned int u_i
Definition: task_arg.h:47
char const * s
Definition: task_arg.h:52
arg_type type
Definition: task_arg.h:43
unsigned long long u_ll
Definition: task_arg.h:49
int i
Definition: task_arg.h:45
task_func func
Definition: task.h:251
linkage l
Definition: task.h:243
TaskAlign * sp
Definition: task.h:256
int interrupt
Definition: task.h:261
int waitfd
Definition: task.h:260
TaskAlign * stack_top
Definition: task.h:255
task_arg arg
Definition: task.h:252
double time
Definition: task.h:257
linkage all
Definition: task.h:244
int taskret
Definition: task.h:250
int refcnt
Definition: task.h:249
int heap_pos
Definition: task.h:245
int debug
Definition: task.h:259
TaskAlign * where
Definition: task.h:254
terminate_enum terminate
Definition: task.h:248
const char * name
Definition: task.h:253
int state
Definition: task.h:215
void * ptr
Definition: task.h:216
int curn
Definition: task.h:270
task_env * x[MAXTASKS+1]
Definition: task.h:271
static double get_double_arg(task_arg arg)
Definition: task.h:140
int task_errno
Definition: task.cc:134
void task_sys_init()
Definition: task.cc:1270
void channel_put(channel *c, linkage *data)
Definition: task.cc:594
static void set_ulong_long_arg(task_arg *arg, unsigned long long value)
Definition: task.h:110
static void set_ulong_arg(task_arg *arg, unsigned long value)
Definition: task.h:105
#define MAXTASKS
Definition: task.h:266
static void set_int_arg(task_arg *arg, int value)
Definition: task.h:75
static task_arg string_arg(char const *v)
Definition: task.h:195
#define TASK_POOL_ELEMS
Definition: task.h:228
void task_wakeup(linkage *queue)
Definition: task.cc:569
static unsigned long long get_ulong_long_arg(task_arg arg)
Definition: task.h:120
task_env * task_deactivate(task_env *t)
Definition: task.cc:716
void popp(task_env *p)
Definition: task.cc:665
result con_write(connection_descriptor const *wfd, void *buf, int n)
Definition: task.cc:978
int unlock_fd(int fd, task_env *t, int lock)
result con_read(connection_descriptor const *rfd, void *buf, int n)
Definition: task.cc:891
static task_arg void_arg(void *v)
Definition: task.h:201
double seconds()
Definition: task.cc:310
static void set_float_arg(task_arg *arg, float value)
Definition: task.h:125
static task_arg uint_arg(unsigned int i)
Definition: task.h:171
static unsigned int get_uint_arg(task_arg arg)
Definition: task.h:100
static task_arg ulong_arg(unsigned long l)
Definition: task.h:177
void channel_put_front(channel *c, linkage *data)
Definition: task.cc:600
terminate_enum
Definition: task.h:230
@ TERMINATED
Definition: task.h:233
@ RUN
Definition: task.h:231
@ KILL
Definition: task.h:232
int(* task_func)(task_arg arg)
Definition: task.h:224
static task_arg int_arg(int i)
Definition: task.h:165
void task_delay_until(double time)
Definition: task.cc:553
task_env * task_terminate(task_env *t)
Definition: task.cc:719
task_env * timed_wait_io(task_env *t, int fd, int op, double timeout)
int task_write(connection_descriptor const *con, void *buf, uint32_t n, int64_t *ret)
Definition: task.cc:1024
int task_read(connection_descriptor const *con, void *buf, int n, int64_t *ret, connnection_read_method read_function=con_read)
Definition: task.cc:934
result con_pipe_read(connection_descriptor const *rfd, void *buf, int n)
Definition: task.cc:917
static void set_string_arg(task_arg *arg, char const *value)
Definition: task.h:145
static task_arg end_arg()
Definition: task.h:207
int is_only_task()
Definition: task.cc:1118
result set_nodelay(int fd)
Definition: xcom_transport.cc:134
result(* connnection_read_method)(connection_descriptor const *rfd, void *buf, int n)
Definition: task.h:554
const char * task_name()
Definition: task.cc:1292
static task_arg ulong_long_arg(unsigned long long ll)
Definition: task.h:183
xcom_proto const my_xcom_version
Definition: xcom_transport.cc:82
result(* connnection_write_method)(connection_descriptor const *rfd, void *buf, int n)
Definition: task.h:564
channel * channel_init(channel *c, unsigned int type)
Definition: task.cc:588
int unblock_fd(int fd)
Definition: task.cc:1080
void reset_state(task_env *p)
Definition: task.cc:645
void remove_and_wakeup(int i)
Definition: task.cc:864
static void set_long_arg(task_arg *arg, long value)
Definition: task.h:85
static void * get_void_arg(task_arg arg)
Definition: task.h:160
void task_wait(task_env *t, linkage *queue)
Definition: task.cc:561
static void set_uint_arg(task_arg *arg, unsigned int value)
Definition: task.h:95
static task_arg double_arg(double i)
Definition: task.h:189
static int get_int_arg(task_arg arg)
Definition: task.h:80
result con_pipe_write(connection_descriptor const *wfd, void *buf, int n)
Definition: task.cc:1006
xcom_proto const my_min_xcom_version
Definition: xcom_transport.cc:80
static float get_float_arg(task_arg arg)
Definition: task.h:130
static long get_long_arg(task_arg arg)
Definition: task.h:90
double task_now()
Definition: task.cc:318
task_env * stack
Definition: task.cc:876
void task_loop()
Definition: task.cc:1139
void * task_allocate(task_env *p, unsigned int bytes)
Allocate bytes from pool, initialized to zero.
Definition: task.cc:627
void set_task(task_env **p, task_env *t)
Definition: task.cc:1286
task_env * task_activate(task_env *t)
Definition: task.cc:714
task_env * task_new(task_func func, task_arg arg, const char *name, int debug)
Definition: task.cc:606
int lock_fd(int fd, task_env *t, int lock)
task_env * wait_io(task_env *t, int fd, int op)
Definition: task.cc:878
int block_fd(int fd)
Definition: task.cc:1098
static char const * get_string_arg(task_arg arg)
Definition: task.h:155
void task_terminate_all()
Definition: task.cc:732
static unsigned long get_ulong_arg(task_arg arg)
Definition: task.h:115
static void set_double_arg(task_arg *arg, double value)
Definition: task.h:135
static void set_void_arg(task_arg *arg, void *value)
Definition: task.h:150
void pushp(task_env *p, void *ptr)
Definition: task.cc:654
@ a_int
Definition: task_arg.h:29
@ a_double
Definition: task_arg.h:35
@ a_end
Definition: task_arg.h:38
@ a_ulong_long
Definition: task_arg.h:33
@ a_uint
Definition: task_arg.h:31
@ a_long
Definition: task_arg.h:30
@ a_void
Definition: task_arg.h:36
@ a_float
Definition: task_arg.h:34
@ a_string
Definition: task_arg.h:37
@ a_ulong
Definition: task_arg.h:32
int n
Definition: xcom_base.cc:509