diff --git a/src/fastlock.cpp b/src/fastlock.cpp index 5a7152b00..bb8621906 100644 --- a/src/fastlock.cpp +++ b/src/fastlock.cpp @@ -45,6 +45,7 @@ #include #include #include "config.h" +#include "serverassert.h" #ifdef __APPLE__ #include @@ -164,7 +165,7 @@ extern "C" pid_t gettid() if (pidCache == -1) { uint64_t tidT; pthread_threadid_np(nullptr, &tidT); - assert(tidT < UINT_MAX); + serverAssert(tidT < UINT_MAX); pidCache = (int)tidT; } #endif @@ -393,7 +394,7 @@ extern "C" void fastlock_unlock(struct fastlock *lock) { int pidT; __atomic_load(&lock->m_pidOwner, &pidT, __ATOMIC_RELAXED); - assert(pidT >= 0); // unlock after free + serverAssert(pidT >= 0); // unlock after free int t = -1; __atomic_store(&lock->m_pidOwner, &t, __ATOMIC_RELEASE); std::atomic_thread_fence(std::memory_order_release); @@ -431,7 +432,7 @@ extern "C" void unlock_futex(struct fastlock *lock, uint16_t ifutex) extern "C" void fastlock_free(struct fastlock *lock) { // NOP - assert((lock->m_ticket.m_active == lock->m_ticket.m_avail) // Asser the lock is unlocked + serverAssert((lock->m_ticket.m_active == lock->m_ticket.m_avail) // Asser the lock is unlocked || (lock->m_pidOwner == gettid() && (lock->m_ticket.m_active == lock->m_ticket.m_avail-1))); // OR we own the lock and nobody else is waiting lock->m_pidOwner = -2; // sentinal value indicating free ANNOTATE_RWLOCK_DESTROY(lock); diff --git a/src/server.h b/src/server.h index a7a1e2adc..9d13311e2 100644 --- a/src/server.h +++ b/src/server.h @@ -92,6 +92,7 @@ typedef long long ustime_t; /* microsecond time type. */ #include "uuid.h" #include "semiorderedset.h" #include "connection.h" /* Connection abstraction */ +#include "serverassert.h" #define REDISMODULE_CORE 1 #include "redismodule.h" /* Redis modules API defines. */ @@ -610,16 +611,6 @@ public: * The actual resolution depends on g_pserver->hz. */ #define run_with_period(_ms_) if ((_ms_ <= 1000/g_pserver->hz) || !(g_pserver->cronloops%((_ms_)/(1000/g_pserver->hz)))) -/* We can print the stacktrace, so our assert is defined this way: */ -#define serverAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_serverAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1))) -#define serverAssert(_e) ((_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),_exit(1))) -#ifdef _DEBUG -#define serverAssertDebug(_e) serverAssert(_e) -#else -#define serverAssertDebug(_e) -#endif -#define serverPanic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),_exit(1) - /*----------------------------------------------------------------------------- * Data types *----------------------------------------------------------------------------*/ @@ -2996,9 +2987,6 @@ void *realloc(void *ptr, size_t size); #endif /* Debugging stuff */ -void _serverAssertWithInfo(const client *c, robj_roptr o, const char *estr, const char *file, int line); -extern "C" void _serverAssert(const char *estr, const char *file, int line); -extern "C" void _serverPanic(const char *file, int line, const char *msg, ...); void bugReportStart(void); void serverLogObjectDebugInfo(robj_roptr o); void sigsegvHandler(int sig, siginfo_t *info, void *secret); diff --git a/src/serverassert.h b/src/serverassert.h new file mode 100644 index 000000000..91223c2b1 --- /dev/null +++ b/src/serverassert.h @@ -0,0 +1,15 @@ +#pragma once + +void _serverAssertWithInfo(const struct client *c, class robj_roptr o, const char *estr, const char *file, int line); +extern "C" void _serverAssert(const char *estr, const char *file, int line); +extern "C" void _serverPanic(const char *file, int line, const char *msg, ...); + +/* We can print the stacktrace, so our assert is defined this way: */ +#define serverAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_serverAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1))) +#define serverAssert(_e) ((_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),_exit(1))) +#ifdef _DEBUG +#define serverAssertDebug(_e) serverAssert(_e) +#else +#define serverAssertDebug(_e) +#endif +#define serverPanic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),_exit(1) \ No newline at end of file