Lely core libraries 2.3.4
ctx.h
Go to the documentation of this file.
1
25#ifndef LELY_IO2_CTX_H_
26#define LELY_IO2_CTX_H_
27
28#include <lely/io2/io2.h>
29#include <lely/util/dllist.h>
30
45
46struct io_svc_vtbl;
47
49struct io_svc {
51 const struct io_svc_vtbl *vptr;
52 int _shutdown;
53 struct dlnode _node;
54};
55
57#define IO_SVC_INIT(vptr) \
58 { \
59 (vptr), 0, { NULL, NULL } \
60 }
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
74 int (*notify_fork)(struct io_svc *svc, enum io_fork_event e);
79 void (*shutdown)(struct io_svc *svc);
80};
81
82void *io_ctx_alloc(void);
83void io_ctx_free(void *ptr);
84io_ctx_t *io_ctx_init(io_ctx_t *ctx);
85void io_ctx_fini(io_ctx_t *ctx);
86
94
96void io_ctx_destroy(io_ctx_t *ctx);
97
105void io_ctx_insert(io_ctx_t *ctx, struct io_svc *svc);
106
117void io_ctx_remove(io_ctx_t *ctx, struct io_svc *svc);
118
132
141void io_ctx_shutdown(io_ctx_t *ctx);
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif // !LELY_IO2_CTX_H_
int io_ctx_notify_fork(io_ctx_t *ctx, enum io_fork_event e)
Notifies all registered I/O services of the specified fork event.
Definition ctx.c:156
void io_ctx_destroy(io_ctx_t *ctx)
Destroys an I/O context.
Definition ctx.c:117
void io_ctx_insert(io_ctx_t *ctx, struct io_svc *svc)
Registers an I/O service with an I/O context.
Definition ctx.c:126
io_ctx_t * io_ctx_create(void)
Creates a new I/O context.
Definition ctx.c:90
void io_ctx_shutdown(io_ctx_t *ctx)
Shuts down all registered I/O services in reverse order of registration.
Definition ctx.c:200
io_fork_event
The type of event generated by an I/O context before and after a process fork.
Definition ctx.h:37
@ IO_FORK_CHILD
The event generated after the fork in the child process.
Definition ctx.h:43
@ IO_FORK_PARENT
The event generated after the fork in the parent process.
Definition ctx.h:41
@ IO_FORK_PREPARE
The event generated before the fork.
Definition ctx.h:39
void io_ctx_remove(io_ctx_t *ctx, struct io_svc *svc)
Unregisters an I/O service with an I/O context.
Definition ctx.c:141
This header file is part of the utilities library; it contains the doubly-linked list declarations.
This is the public header file of the I/O library.
A node in a doubly-linked list.
Definition dllist.h:40
Definition ctx.c:38
The virtual table of an I/O service.
Definition ctx.h:67
int(* notify_fork)(struct io_svc *svc, enum io_fork_event e)
A pointer to the function to be called by io_ctx_notify_fork() (can be NULL).
Definition ctx.h:74
void(* shutdown)(struct io_svc *svc)
A pointer to the function to be called by io_ctx_shutdown() (can be NULL).
Definition ctx.h:79
An I/O service.
Definition ctx.h:49
const struct io_svc_vtbl * vptr
A pointer to the virtual table for the I/O service.
Definition ctx.h:51