Fix mac build breaks

Former-commit-id: 16a89f21dc0beb23b7eb8f2e378d076da918c0d6
This commit is contained in:
John Sully 2019-06-27 15:04:09 -04:00
parent 9252500928
commit 15d37f3d65
3 changed files with 13 additions and 1 deletions

View File

@ -140,6 +140,7 @@ else
# All the other OSes (notably Linux)
FINAL_LDFLAGS+= -rdynamic
FINAL_LIBS+=-ldl -pthread -lrt -luuid
FINAL_CFLAGS += -DMOTD
endif
endif
endif

View File

@ -36,7 +36,9 @@
#include <assert.h>
#include <pthread.h>
#include <limits.h>
#ifdef __linux__
#include <linux/futex.h>
#endif
#include <string.h>
#ifdef __APPLE__
@ -67,6 +69,7 @@ uint64_t fastlock_getlongwaitcount()
}
#ifndef ASM_SPINLOCK
#ifdef __linux__
static int futex(volatile unsigned *uaddr, int futex_op, int val,
const struct timespec *timeout, int val3)
{
@ -74,6 +77,7 @@ static int futex(volatile unsigned *uaddr, int futex_op, int val,
timeout, uaddr, val3);
}
#endif
#endif
extern "C" pid_t gettid()
{
@ -121,9 +125,11 @@ extern "C" void fastlock_lock(struct fastlock *lock)
#endif
if ((++cloops % 1024*1024) == 0)
{
#ifdef __linux__
__atomic_fetch_or(&lock->futex, mask, __ATOMIC_ACQUIRE);
futex(&lock->m_ticket.u, FUTEX_WAIT_BITSET_PRIVATE, ticketT.u, nullptr, mask);
__atomic_fetch_and(&lock->futex, ~mask, __ATOMIC_RELEASE);
#endif
++g_longwaits;
}
}
@ -159,6 +165,7 @@ extern "C" int fastlock_trylock(struct fastlock *lock, int fWeak)
return false;
}
#ifdef __linux__
#define ROL32(v, shift) ((v << shift) | (v >> (32-shift)))
void unlock_futex(struct fastlock *lock, uint16_t ifutex)
{
@ -174,6 +181,8 @@ void unlock_futex(struct fastlock *lock, uint16_t ifutex)
break;
}
}
#endif
extern "C" void fastlock_unlock(struct fastlock *lock)
{
--lock->m_depth;
@ -183,7 +192,9 @@ extern "C" void fastlock_unlock(struct fastlock *lock)
lock->m_pidOwner = -1;
std::atomic_thread_fence(std::memory_order_release);
uint16_t activeNew = __atomic_add_fetch(&lock->m_ticket.m_active, 1, __ATOMIC_RELEASE); // on x86 the atomic is not required here, but ASM handles that case
#ifdef __linux__
unlock_futex(lock, activeNew);
#endif
}
}
#endif

View File

@ -6537,7 +6537,7 @@ static void intrinsicLatencyMode(void) {
/*------------------------------------------------------------------------------
* Message of the day
*--------------------------------------------------------------------------- */
#ifndef NO_MOTD
#ifdef MOTD
#include <curl/curl.h>
static const char *szMotdCachePath()