21#include "xtc_export.h"
36typedef struct xtc_pid {
42#define XTC_PID_NONE ((xtc_pid_t){0, 0, 0})
47 return a.loop_id == b.loop_id &&
48 a.local_id == b.local_id &&
55 return p.loop_id == 0 && p.local_id == 0 && p.gen == 0;
64typedef int (*xtc_match_fn)(
const void *data,
size_t size,
void *user_data);
71typedef void (*xtc_proc_fn)(
void *arg);
73typedef struct xtc_proc_opts {
83 int mailbox_watermark_pct;
84 void (*mailbox_watermark_fn)(
xtc_pid_t self,
size_t depth,
85 size_t cap,
void *user);
86 void *mailbox_watermark_user;
105 xtc_exec_class_t sched_class;
109typedef struct xtc_mailbox_stats {
141XTC_API
int xtc_proc_spawn(xtc_loop_t *loop, xtc_proc_fn fn,
void *arg,
161XTC_API
int xtc_proc_spawn_link(xtc_loop_t *loop, xtc_proc_fn fn,
void *arg,
163XTC_API
int xtc_proc_spawn_monitor(xtc_loop_t *loop, xtc_proc_fn fn,
174XTC_API
int xtc_exit_pid(
xtc_pid_t target,
int reason);
188XTC_API
int xtc_proc_wake(
xtc_pid_t target);
214XTC_API
int xtc_proc_set_userdata(
void *ud);
215XTC_API
void *xtc_proc_userdata(
void);
226XTC_API
int xtc_proc_set_class(xtc_exec_class_t cls);
252XTC_API
int xtc_send(
xtc_pid_t to,
const void *data,
size_t size);
266XTC_API
int xtc_recv(
void **out,
size_t *out_size, int64_t timeout_ns);
273XTC_API
int xtc_recv_match(xtc_match_fn match_fn,
void *user_data,
274 void **out,
size_t *out_size,
295typedef struct xtc_msg {
300XTC_API
int xtc_recv_correlate(
const void *corr_value,
size_t corr_size,
327#define XTC_WAIT_MAILBOX 0x10000u
328#define XTC_WAIT_TIMEOUT 0x20000u
330XTC_API
int xtc_proc_wait_fd(
int fd, uint32_t interest, int64_t timeout_ns,
331 uint32_t *out_revents);
337XTC_API
int xtc_proc_sleep(int64_t ns);
341XTC_API
int xtc_exit_self(
int reason);
372#define XTC_DOWN_NOPROC (-100000)
375xtc_down_is_noproc(
int reason)
377 return reason == XTC_DOWN_NOPROC;
386XTC_API
int xtc_monitor(
xtc_pid_t target, uint64_t *out_ref);
410#if (defined(__sun) || defined(__illumos__)) && !defined(__EXTENSIONS__)
416#define __EXTENSIONS__ 1
441int xtc_fault_guard_install(
void);
452void __xtc_recovery_prep(
void);
453CONTEXT *__xtc_recovery_ctx(
void);
454int __xtc_recovery_result(
void);
487#define xtc_proc_recovery_arm() \
488 (__xtc_recovery_prep(), \
489 RtlCaptureContext(__xtc_recovery_ctx()), \
490 __xtc_recovery_result())
492#define xtc_proc_recovery_arm() (sigsetjmp(*__xtc_proc_recovery_slot(), 1))
496void xtc_proc_recovery_disarm(
void);
501void xtc_proc_critical_enter(
void);
502void xtc_proc_critical_leave(
void);
513int xtc_proc_at_exit(
void (*fn)(
void *),
void *arg);
519struct xtc_mctx *xtc_proc_mctx(
void);
559int xtc_proc_recovery_track_fd(
int fd);
560int xtc_proc_recovery_track_mctx(
struct xtc_mctx *mctx);
561int xtc_proc_recovery_track_locks(
void *mgr, uint64_t locker,
562 void (*release_all)(
void *, uint64_t));
563int xtc_proc_recovery_track(
void (*fn)(
void *),
void *arg);
564int xtc_proc_recovery_untrack_fd(
int fd);
565void xtc_proc_recovery_cleanup(
void);
576#define xtc_proc_recovery_arm_clean() \
578 int __xtc_rsig = xtc_proc_recovery_arm(); \
579 if (__xtc_rsig != 0) { \
580 xtc_proc_recovery_cleanup(); \
581 (void)xtc_exit_self(__xtc_rsig); \
602XTC_API
int xtc_uncancelable(
int (*body)(
void *),
void *ud);
614XTC_API
int xtc_cancel_poll(
int (*body)(
void *),
void *ud);
625XTC_API
int xtc_cancel_requested(
void);
644typedef struct xtc_scope xtc_scope_t;
645typedef void (*xtc_finalizer_fn)(
void *arg);
652XTC_API xtc_scope_t *xtc_scope_open(
void);
653XTC_API
int xtc_scope_defer(xtc_scope_t *s, xtc_finalizer_fn fn,
void *arg);
654XTC_API
void xtc_scope_close(xtc_scope_t *s);
667XTC_API
int xtc_bracket(
int (*acquire)(
void **res,
void *ud),
668 int (*use)(
void *res,
void *ud),
669 void (*release)(
void *res,
void *ud),
677int xtc_down_decode(
const void *msg,
size_t len,
691 XTC_DOWN_KIND_CLEAN = 0,
692 XTC_DOWN_KIND_EXIT = 1,
693 XTC_DOWN_KIND_SIGNAL = 2,
694 XTC_DOWN_KIND_NOPROC = 3,
695 XTC_DOWN_KIND_NOCONNECTION = 4
703 xtc_down_kind_t kind;
719XTC_API
int xtc_down_decode_ex(
const void *msg,
size_t len,
727static inline int xtc_down_is_signal_reason(
int reason)
729 return reason >= 1 && reason <= 255;
731static inline int xtc_down_is_exit_reason(
int reason)
733 return reason == 0 || reason >= 256;