From 69f375c45baa009c37b1069cbd75a1a5c046f5c4 Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 11 Dec 2020 00:24:27 +0000 Subject: [PATCH] Remove AE_ASSERT and use the proper assert infra Former-commit-id: a80dd5d0010d87bd7dbfb7e2ccbca98a8511db69 --- src/ae.cpp | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/ae.cpp b/src/ae.cpp index cb500d7b6..4a23ada30 100644 --- a/src/ae.cpp +++ b/src/ae.cpp @@ -48,6 +48,7 @@ #include "fastlock.h" #include "zmalloc.h" #include "config.h" +#include "serverassert.h" #ifdef USE_MUTEX thread_local int cOwnLock = 0; @@ -84,8 +85,6 @@ fastlock g_lock("AE (global)"); #endif thread_local aeEventLoop *g_eventLoopThisThread = NULL; -#define AE_ASSERT(x) if (!(x)) do { fprintf(stderr, "AE_ASSERT FAILURE %s: %d\n", __FILE__, __LINE__); *((volatile int*)1) = 1; } while(0) - /* Include the best multiplexing layer supported by this system. * The following should be ordered by performances, descending. */ #ifdef HAVE_EVPORT @@ -140,7 +139,7 @@ void aeProcessCmd(aeEventLoop *eventLoop, int fd, void *, int ) auto cb = read(fd, &cmd, sizeof(aeCommand)); if (cb != sizeof(cmd)) { - AE_ASSERT(errno == EAGAIN); + serverAssert(errno == EAGAIN); break; } switch (cmd.op) @@ -251,8 +250,8 @@ int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask, auto size = safe_write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd)); if (size != sizeof(cmd)) { - AE_ASSERT(size == sizeof(cmd) || size <= 0); - AE_ASSERT(errno == EAGAIN); + serverAssert(size == sizeof(cmd) || size <= 0); + serverAssert(errno == EAGAIN); ret = AE_ERR; } @@ -307,9 +306,14 @@ int aePostFunction(aeEventLoop *eventLoop, std::function fn, bool fSynch } auto size = write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd)); - if (size != sizeof(cmd)) + if (!(!size || size == sizeof(cmd))) { + printf("Last error: %d\n", errno); + } + serverAssert(!size || size == sizeof(cmd)); + + if (size == 0) return AE_ERR; - AE_ASSERT(size == sizeof(cmd)); + int ret = AE_OK; if (fSynchronous) { @@ -352,7 +356,7 @@ aeEventLoop *aeCreateEventLoop(int setsize) { goto err; eventLoop->fdCmdRead = rgfd[0]; eventLoop->fdCmdWrite = rgfd[1]; - fcntl(eventLoop->fdCmdWrite, F_SETFL, O_NONBLOCK); + //fcntl(eventLoop->fdCmdWrite, F_SETFL, O_NONBLOCK); fcntl(eventLoop->fdCmdRead, F_SETFL, O_NONBLOCK); eventLoop->cevents = 0; aeCreateFileEvent(eventLoop, eventLoop->fdCmdRead, AE_READABLE|AE_READ_THREADSAFE, aeProcessCmd, NULL); @@ -389,7 +393,7 @@ void aeSetDontWait(aeEventLoop *eventLoop, int noWait) { * * Otherwise AE_OK is returned and the operation is successful. */ int aeResizeSetSize(aeEventLoop *eventLoop, int setsize) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); int i; if (setsize == eventLoop->setsize) return AE_OK; @@ -427,14 +431,14 @@ extern "C" void aeDeleteEventLoop(aeEventLoop *eventLoop) { } extern "C" void aeStop(aeEventLoop *eventLoop) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); eventLoop->stop = 1; } extern "C" int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask, aeFileProc *proc, void *clientData) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); if (fd >= eventLoop->setsize) { errno = ERANGE; return AE_ERR; @@ -463,12 +467,12 @@ void aeDeleteFileEventAsync(aeEventLoop *eventLoop, int fd, int mask) cmd.mask = mask; cmd.fLock = true; auto cb = write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd)); - AE_ASSERT(cb == sizeof(cmd)); + serverAssert(cb == sizeof(cmd)); } extern "C" void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); if (fd >= eventLoop->setsize) return; aeFileEvent *fe = &eventLoop->events[fd]; if (fe->mask == AE_NONE) return; @@ -526,7 +530,7 @@ extern "C" long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long millise aeTimeProc *proc, void *clientData, aeEventFinalizerProc *finalizerProc) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); long long id = eventLoop->timeEventNextId++; aeTimeEvent *te; @@ -548,7 +552,7 @@ extern "C" long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long millise extern "C" int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); aeTimeEvent *te = eventLoop->timeEventHead; while(te) { if (te->id == id) { @@ -573,7 +577,7 @@ extern "C" int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id) */ static aeTimeEvent *aeSearchNearestTimer(aeEventLoop *eventLoop) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); aeTimeEvent *te = eventLoop->timeEventHead; aeTimeEvent *nearest = NULL; @@ -749,7 +753,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma * The function returns the number of events processed. */ int aeProcessEvents(aeEventLoop *eventLoop, int flags) { - AE_ASSERT(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); + serverAssert(g_eventLoopThisThread == NULL || g_eventLoopThisThread == eventLoop); int processed = 0, numevents; /* Nothing to do? return ASAP */ @@ -873,9 +877,9 @@ void aeMain(aeEventLoop *eventLoop) { ulock.lock(); eventLoop->beforesleep(eventLoop); } - AE_ASSERT(!aeThreadOwnsLock()); // we should have relinquished it after processing + serverAssert(!aeThreadOwnsLock()); // we should have relinquished it after processing aeProcessEvents(eventLoop, AE_ALL_EVENTS|AE_CALL_AFTER_SLEEP); - AE_ASSERT(!aeThreadOwnsLock()); // we should have relinquished it after processing + serverAssert(!aeThreadOwnsLock()); // we should have relinquished it after processing } }