diff --git a/src/Makefile b/src/Makefile index 70e297929..57cd3a0c7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -94,7 +94,7 @@ endif FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) FINAL_CXXFLAGS=$(CXX_STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(CXXFLAGS) $(REDIS_CFLAGS) FINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG) -FINAL_LIBS=-lm -luuid +FINAL_LIBS=-lm DEBUG=-g -ggdb ifeq ($(uname_S),SunOS) @@ -139,7 +139,7 @@ ifeq ($(uname_S),DragonFly) else # All the other OSes (notably Linux) FINAL_LDFLAGS+= -rdynamic - FINAL_LIBS+=-ldl -pthread -lrt + FINAL_LIBS+=-ldl -pthread -lrt -luuid endif endif endif diff --git a/src/ae_kqueue.c b/src/ae_kqueue.c index 200bbd09e..5c83f6464 100644 --- a/src/ae_kqueue.c +++ b/src/ae_kqueue.c @@ -39,10 +39,10 @@ typedef struct aeApiState { } aeApiState; static int aeApiCreate(aeEventLoop *eventLoop) { - aeApiState *state = zmalloc(sizeof(aeApiState), MALLOC_LOCAL); + aeApiState *state = (aeApiState*)zmalloc(sizeof(aeApiState), MALLOC_LOCAL); if (!state) return -1; - state->events = zmalloc(sizeof(struct kevent)*eventLoop->setsize, MALLOC_LOCAL); + state->events = (struct kevent*)zmalloc(sizeof(struct kevent)*eventLoop->setsize, MALLOC_LOCAL); if (!state->events) { zfree(state); return -1; @@ -58,14 +58,14 @@ static int aeApiCreate(aeEventLoop *eventLoop) { } static int aeApiResize(aeEventLoop *eventLoop, int setsize) { - aeApiState *state = eventLoop->apidata; + aeApiState *state = (aeApiState*)eventLoop->apidata; - state->events = zrealloc(state->events, sizeof(struct kevent)*setsize, MALLOC_LOCAL); + state->events = (struct kevent*)zrealloc(state->events, sizeof(struct kevent)*setsize, MALLOC_LOCAL); return 0; } static void aeApiFree(aeEventLoop *eventLoop) { - aeApiState *state = eventLoop->apidata; + aeApiState *state = (aeApiState*)eventLoop->apidata; close(state->kqfd); zfree(state->events); @@ -73,7 +73,7 @@ static void aeApiFree(aeEventLoop *eventLoop) { } static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) { - aeApiState *state = eventLoop->apidata; + aeApiState *state = (aeApiState*)eventLoop->apidata; struct kevent ke; if (mask & AE_READABLE) { @@ -88,7 +88,7 @@ static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) { } static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) { - aeApiState *state = eventLoop->apidata; + aeApiState *state = (aeApiState*)eventLoop->apidata; struct kevent ke; if (mask & AE_READABLE) { @@ -102,7 +102,7 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) { } static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) { - aeApiState *state = eventLoop->apidata; + aeApiState *state = (aeApiState*)eventLoop->apidata; int retval, numevents = 0; if (tvp != NULL) { @@ -133,6 +133,6 @@ static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) { return numevents; } -static char *aeApiName(void) { +static const char *aeApiName(void) { return "kqueue"; } diff --git a/src/fastlock.cpp b/src/fastlock.cpp index dcbcff688..f1e13a279 100644 --- a/src/fastlock.cpp +++ b/src/fastlock.cpp @@ -34,6 +34,20 @@ #include #include #include +#include +#include + +#ifdef __APPLE__ +#include +#ifdef TARGET_OS_MAC +/* The CLANG that ships with Mac OS doesn't have these builtins. + but on x86 they are just normal reads/writes anyways */ +#define __atomic_load_4(ptr, csq) (*(reinterpret_cast(ptr))) +#define __atomic_load_2(ptr, csq) (*(reinterpret_cast(ptr))) + +#define __atomic_store_4(ptr, val, csq) (*(reinterpret_cast(ptr)) = val) +#endif +#endif /**************************************************** * @@ -54,8 +68,17 @@ uint64_t fastlock_getlongwaitcount() extern "C" pid_t gettid() { static thread_local int pidCache = -1; +#ifdef __linux__ if (pidCache == -1) pidCache = syscall(SYS_gettid); +#else + if (pidCache == -1) { + uint64_t tidT; + pthread_threadid_np(nullptr, &tidT); + assert(tidT < UINT_MAX); + pidCache = (int)tidT; + } +#endif return pidCache; } diff --git a/src/server.cpp b/src/server.cpp index 9e3d9d6ad..357c4d3cb 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -5076,6 +5076,7 @@ int main(int argc, char **argv) { pthread_create(rgthread + iel, NULL, workerThreadMain, (void*)((int64_t)iel)); if (server.fThreadAffinity) { +#ifdef __linux__ cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(iel, &cpuset); @@ -5083,6 +5084,9 @@ int main(int argc, char **argv) { { serverLog(LOG_INFO, "Binding thread %d to cpu %d", iel, iel); } +#else + serverLog(LL_WARNING, "CPU pinning not available on this platform"); +#endif } } void *pvRet; diff --git a/src/storage-lite.c b/src/storage-lite.c index cee5ffc91..1f9492089 100644 --- a/src/storage-lite.c +++ b/src/storage-lite.c @@ -1,12 +1,13 @@ #include #include #include -#include #include #include #include "storage.h" #include +#ifdef __linux__ #include +#endif // initialize the memory subsystem. // NOTE: This may be called twice, first with NULL specifying we should use ram @@ -42,7 +43,9 @@ void *srealloc(void *pv, size_t cb, enum MALLOC_CLASS class) return realloc(pv, cb); } +#ifdef __linux__ size_t salloc_usable_size(void *ptr) { return malloc_usable_size(ptr); } +#endif