From 4030a9fb2eb699361c58d71878e97b282647319a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 18 Feb 2022 15:13:56 +0200 Subject: [PATCH] MDEV-26476: Implement futex for FreeBSD, DragonFly BSD --- storage/innobase/include/rw_lock.h | 16 ++++++++++++---- storage/innobase/sync/srw_lock.cc | 13 ++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/storage/innobase/include/rw_lock.h b/storage/innobase/include/rw_lock.h index a9099d10670..70607b979c1 100644 --- a/storage/innobase/include/rw_lock.h +++ b/storage/innobase/include/rw_lock.h @@ -1,6 +1,6 @@ /***************************************************************************** -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 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., #include #include "my_dbug.h" -#if !(defined __linux__ || defined __OpenBSD__ || defined _WIN32) -# define SUX_LOCK_GENERIC -#elif 0 // defined SAFE_MUTEX +#if defined __linux__ +/* futex(2): FUTEX_WAIT_PRIVATE, FUTEX_WAKE_PRIVATE */ +#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 */ #endif diff --git a/storage/innobase/sync/srw_lock.cc b/storage/innobase/sync/srw_lock.cc index 71414e8ddb2..f406b04712a 100644 --- a/storage/innobase/sync/srw_lock.cc +++ b/storage/innobase/sync/srw_lock.cc @@ -1,6 +1,6 @@ /***************************************************************************** -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 the terms of the GNU General Public License as published by the Free Software @@ -339,6 +339,17 @@ void ssux_lock_impl::wake() { WakeByAddressSingle(&readers); } # include # define SRW_FUTEX(a,op,n) \ futex((volatile uint32_t*) a, FUTEX_ ## op, n, nullptr, nullptr) +# elif defined __FreeBSD__ +# include +# include +# 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 +# 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 # error "no futex support" # endif