MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / aeCreateEventLoop

Function aeCreateEventLoop

src/ae.cpp:313–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313aeEventLoop *aeCreateEventLoop(int setsize) {
314 aeEventLoop *eventLoop;
315 int i;
316
317 monotonicInit(); /* just in case the calling app didn't initialize */
318
319 if ((eventLoop = (aeEventLoop*)zmalloc(sizeof(*eventLoop), MALLOC_LOCAL)) == NULL) goto err;
320 eventLoop->events = (aeFileEvent*)zmalloc(sizeof(aeFileEvent)*setsize, MALLOC_LOCAL);
321 eventLoop->fired = (aeFiredEvent*)zmalloc(sizeof(aeFiredEvent)*setsize, MALLOC_LOCAL);
322 if (eventLoop->events == NULL || eventLoop->fired == NULL) goto err;
323 eventLoop->setsize = setsize;
324 eventLoop->timeEventHead = NULL;
325 eventLoop->timeEventNextId = 0;
326 eventLoop->stop = 0;
327 eventLoop->maxfd = -1;
328 eventLoop->beforesleep = NULL;
329 eventLoop->aftersleep = NULL;
330 eventLoop->flags = 0;
331 if (aeApiCreate(eventLoop) == -1) goto err;
332 /* Events with mask == AE_NONE are not set. So let's initialize the
333 * vector with it. */
334 for (i = 0; i < setsize; i++)
335 eventLoop->events[i].mask = AE_NONE;
336
337 fastlock_init(&eventLoop->flock, "event loop");
338 int rgfd[2];
339 if (pipe(rgfd) < 0)
340 goto err;
341 eventLoop->fdCmdRead = rgfd[0];
342 eventLoop->fdCmdWrite = rgfd[1];
343 //fcntl(eventLoop->fdCmdWrite, F_SETFL, O_NONBLOCK);
344 fcntl(eventLoop->fdCmdRead, F_SETFL, O_NONBLOCK);
345 eventLoop->cevents = 0;
346 aeCreateFileEvent(eventLoop, eventLoop->fdCmdRead, AE_READABLE|AE_READ_THREADSAFE, aeProcessCmd, NULL);
347
348 return eventLoop;
349
350err:
351 if (eventLoop) {
352 zfree(eventLoop->events);
353 zfree(eventLoop->fired);
354 zfree(eventLoop);
355 }
356 return NULL;
357}
358
359/* Return the current set size. */
360int aeGetSetSize(aeEventLoop *eventLoop) {

Callers 6

createBenchmarkThreadFunction · 0.85
initConfigDefaultsFunction · 0.85
createBenchmarkThreadFunction · 0.85
mainFunction · 0.85
initServerThreadFunction · 0.85
mainFunction · 0.85

Calls 6

monotonicInitFunction · 0.85
zmallocFunction · 0.85
fastlock_initFunction · 0.85
aeCreateFileEventFunction · 0.85
zfreeFunction · 0.85
aeApiCreateFunction · 0.70

Tested by

no test coverage detected