Commit 4030a9fb authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-26476: Implement futex for FreeBSD, DragonFly BSD

parent f04b459f
/***************************************************************************** /*****************************************************************************
Copyright (c) 2020, 2021, MariaDB Corporation. Copyright (c) 2020, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -20,9 +20,17 @@ this program; if not, write to the Free Software Foundation, Inc., ...@@ -20,9 +20,17 @@ this program; if not, write to the Free Software Foundation, Inc.,
#include <atomic> #include <atomic>
#include "my_dbug.h" #include "my_dbug.h"
#if !(defined __linux__ || defined __OpenBSD__ || defined _WIN32) #if defined __linux__
# define SUX_LOCK_GENERIC /* futex(2): FUTEX_WAIT_PRIVATE, FUTEX_WAKE_PRIVATE */
#elif 0 // defined SAFE_MUTEX #elif defined __OpenBSD__ || defined __FreeBSD__ || defined __DragonFly__
/* system calls similar to Linux futex(2) */
#elif defined _WIN32
/* SRWLOCK as well as WaitOnAddress(), WakeByAddressSingle() */
#else
# define SUX_LOCK_GENERIC /* fall back to generic synchronization primitives */
#endif
#if !defined SUX_LOCK_GENERIC && 0 /* defined SAFE_MUTEX */
# define SUX_LOCK_GENERIC /* Use dummy implementation for debugging purposes */ # define SUX_LOCK_GENERIC /* Use dummy implementation for debugging purposes */
#endif #endif
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2020, 2021, MariaDB Corporation. Copyright (c) 2020, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -339,6 +339,17 @@ void ssux_lock_impl<spinloop>::wake() { WakeByAddressSingle(&readers); } ...@@ -339,6 +339,17 @@ void ssux_lock_impl<spinloop>::wake() { WakeByAddressSingle(&readers); }
# include <sys/futex.h> # include <sys/futex.h>
# define SRW_FUTEX(a,op,n) \ # define SRW_FUTEX(a,op,n) \
futex((volatile uint32_t*) a, FUTEX_ ## op, n, nullptr, nullptr) futex((volatile uint32_t*) a, FUTEX_ ## op, n, nullptr, nullptr)
# elif defined __FreeBSD__
# include <sys/types.h>
# include <sys/umtx.h>
# define FUTEX_WAKE UMTX_OP_WAKE_PRIVATE
# define FUTEX_WAIT UMTX_OP_WAIT_UINT_PRIVATE
# define SRW_FUTEX(a,op,n) _umtx_op(a, FUTEX_ ## op, n, nullptr, nullptr)
# elif defined __DragonFly__
# include <unistd.h>
# define FUTEX_WAKE(a,n) umtx_wakeup(a,n)
# define FUTEX_WAIT(a,n) umtx_sleep(a,n,0)
# define SRW_FUTEX(a,op,n) FUTEX_ ## op((volatile int*) a, int(n))
# else # else
# error "no futex support" # error "no futex support"
# endif # endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment