Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/mongo/platform/waitable_atomic.cpp
Original file line number Diff line number Diff line change
@@ -34,6 +34,9 @@
#ifdef __linux__
#include <linux/futex.h>
#include <sys/syscall.h>
#elif defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/umtx.h>
#elif defined(_WIN32)
#include <synchapi.h>
#endif
@@ -235,6 +238,45 @@ bool waitUntil(const void* uaddr,
return timeoutOverflow || errno != ETIMEDOUT;
}

#elif defined(__FreeBSD__)

void notifyOne(const void* uaddr) {
_umtx_op(const_cast<void*>(uaddr), UMTX_OP_WAKE_PRIVATE, 1, NULL, NULL);
}

void notifyMany(const void* uaddr, int nToWake) {
_umtx_op(const_cast<void*>(uaddr), UMTX_OP_WAKE_PRIVATE, nToWake, NULL, NULL);
}

void notifyAll(const void* uaddr) {
_umtx_op(const_cast<void*>(uaddr), UMTX_OP_WAKE_PRIVATE, INT_MAX, NULL, NULL);
}

bool waitUntil(const void* uaddr,
uint32_t old,
boost::optional<system_clock::time_point> deadline) {
struct _umtx_time umtx_deadline;
void* uaddr2 = nullptr;

if (deadline) {
umtx_deadline._timeout.tv_sec = durationCount<Seconds>(deadline->time_since_epoch());
umtx_deadline._timeout.tv_nsec = durationCount<Nanoseconds>(
deadline->time_since_epoch() - stdx::chrono::seconds(umtx_deadline._timeout.tv_sec));
umtx_deadline._flags = UMTX_ABSTIME;
umtx_deadline._clockid = CLOCK_REALTIME_FAST;
uaddr2 = &umtx_deadline;
}

int umtxOpRet;
if ((umtxOpRet = _umtx_op(const_cast<void*>(uaddr), UMTX_OP_WAIT_UINT_PRIVATE, old, (void*)sizeof(struct _umtx_time), uaddr2)) != 0) {
if (errno == ETIMEDOUT) {
return false;
}
invariant(umtxOpRet == 0, errorMessage(lastSystemError()));
}
return true;
}

#else
#error "Need an implementation of waitUntil(), notifyOne(), notifyMany(), notifyAll() for this OS"
#endif