UCX 1.17
Unified Communication X
Loading...
Searching...
No Matches
callbackq.h
1
8#ifndef UCS_CALLBACKQ_H
9#define UCS_CALLBACKQ_H
10
11#include <ucs/datastruct/list.h>
12#include <ucs/sys/compiler_def.h>
13#include <ucs/type/status.h>
14#include <stddef.h>
15#include <stdint.h>
16
17BEGIN_C_DECLS
18
21/*
22 * Thread-safe callback queue:
23 * - only one thread can dispatch
24 * - any thread can add and remove
25 * - add/remove operations are O(1)
26 */
27
28#define UCS_CALLBACKQ_FAST_COUNT 7 /* Max. number of fast-path callbacks */
29#define UCS_CALLBACKQ_ID_NULL (-1) /* Invalid callback identifier */
30
31
32/*
33 * Forward declarations
34 */
35typedef struct ucs_callbackq ucs_callbackq_t;
37typedef struct ucs_callbackq_priv ucs_callbackq_priv_t;
38typedef void * ucs_callbackq_key_t;
39
40
50typedef unsigned (*ucs_callback_t)(void *arg);
51
52
61typedef int (*ucs_callbackq_predicate_t)(const ucs_callbackq_elem_t *elem,
62 void *arg);
63
64
69 ucs_callback_t cb;
70 void *arg;
71};
72
73
82 ucs_callbackq_elem_t fast_elems[UCS_CALLBACKQ_FAST_COUNT + 1];
83
88 ucs_callbackq_priv_t *priv;
89};
90
91
97ucs_status_t ucs_callbackq_init(ucs_callbackq_t *cbq);
98
99
105void ucs_callbackq_cleanup(ucs_callbackq_t *cbq);
106
107
120int ucs_callbackq_add(ucs_callbackq_t *cbq, ucs_callback_t cb, void *arg);
121
122
135void *ucs_callbackq_remove(ucs_callbackq_t *cbq, int id);
136
137
150int ucs_callbackq_add_safe(ucs_callbackq_t *cbq, ucs_callback_t cb, void *arg);
151
152
165void *ucs_callbackq_remove_safe(ucs_callbackq_t *cbq, int id);
166
167
181void ucs_callbackq_add_oneshot(ucs_callbackq_t *cbq, ucs_callbackq_key_t key,
182 ucs_callback_t cb, void *arg);
183
184
195void ucs_callbackq_remove_oneshot(ucs_callbackq_t *cbq, ucs_callbackq_key_t key,
196 ucs_callbackq_predicate_t pred, void *arg);
197
198
207static inline unsigned ucs_callbackq_dispatch(ucs_callbackq_t *cbq)
208{
210 ucs_callback_t cb;
211 unsigned count;
212
213 count = 0;
214 for (elem = cbq->fast_elems; (cb = elem->cb) != NULL; ++elem) {
215 count += cb(elem->arg);
216 }
217 return count;
218}
219
220END_C_DECLS
221
222#endif
ucs_status_t
Status codes.
Definition status.h:45
ucs_callbackq_elem_t fast_elems[UCS_CALLBACKQ_FAST_COUNT+1]
Definition callbackq.h:82
ucs_callbackq_priv_t * priv
Definition callbackq.h:88
ucs_callback_t cb
Definition callbackq.h:69
void * arg
Definition callbackq.h:70
Definition callbackq.h:77
Definition callbackq.h:68