MCPcopy Create free account
hub / github.com/acl-dev/acl / kqueue_alloc

Function kqueue_alloc

lib_fiber/c/src/hook/kqueue.c:218–259  ·  view source on GitHub ↗

Create one KQUEUE for the specified kqfd. Allocate and initialize a KQUEUE object for a kqueue fd.

Source from the content-addressed store, hash-verified

216// Create one KQUEUE for the specified kqfd.
217// Allocate and initialize a KQUEUE object for a kqueue fd.
218static KQUEUE *kqueue_alloc(int kqfd)
219{
220 KQUEUE *kq;
221 int maxfd = open_limit(0), i;
222
223 if (maxfd <= 0) {
224 msg_fatal("%s(%d), %s: open_limit error %s",
225 __FILE__, __LINE__, __FUNCTION__, last_serror());
226 }
227
228 /* Using thread local to store the kqueue handles for each thread. */
229 if (__kqfds == NULL) {
230 if (pthread_once(&__once_control, thread_init) != 0) {
231 msg_error("%s(%d), %s: pthread_once error %s",
232 __FILE__, __LINE__, __FUNCTION__, last_serror());
233 return NULL;
234 }
235
236 __kqfds = array_create(5, ARRAY_F_UNORDER);
237 if (thread_self() == main_thread_self()) {
238 __main_kqfds = __kqfds;
239 atexit(main_thread_free);
240 } else if (pthread_setspecific(__once_key, __kqfds) != 0) {
241 msg_error("pthread_setspecific error!");
242 return NULL;
243 }
244 }
245
246 kq = (KQUEUE*) mem_malloc(sizeof(KQUEUE));
247 array_append(__kqfds, kq);
248
249 kq->kqfd = kqfd;
250 kq->nfds = maxfd;
251 kq->fds = (KQUEUE_CTX **) mem_malloc(maxfd * sizeof(KQUEUE_CTX *));
252
253 for (i = 0; i < maxfd; i++) {
254 kq->fds[i] = NULL;
255 }
256
257 ring_init(&kq->kes);
258 return kq;
259}
260
261// Release a KQUEUE object and its fd table.
262static void kqueue_free(KQUEUE *kq)

Callers 2

kqueue_try_registerFunction · 0.85
kqueueFunction · 0.85

Calls 12

open_limitFunction · 0.85
msg_fatalFunction · 0.85
pthread_onceFunction · 0.85
array_createFunction · 0.85
thread_selfFunction · 0.85
main_thread_selfFunction · 0.85
pthread_setspecificFunction · 0.85
mem_mallocFunction · 0.85
array_appendFunction · 0.85
ring_initFunction · 0.85
last_serrorFunction · 0.50
msg_errorFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…