mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
NetBSD specific atomic operation implementation
Signed-off-by: Lennart Poettering <lennart@poettering.net>
This commit is contained in:
parent
cc425ed260
commit
8d89ccdcf2
2 changed files with 150 additions and 53 deletions
24
configure.ac
24
configure.ac
|
|
@ -129,12 +129,27 @@ AC_ARG_ENABLE([atomic-arm-memory-barrier],
|
|||
esac
|
||||
],)
|
||||
|
||||
AC_ARG_ENABLE([netbsd-atomic-ops],
|
||||
AS_HELP_STRING([--enable-netbsd-atomic-ops],[Use the native NetBSD atomic_ops implementation]),
|
||||
[
|
||||
case "${enableval}" in
|
||||
yes) atomic_netbsd_helpers=yes ;;
|
||||
no) atomic_netbsd_helpers=no ;;
|
||||
*) AC_MSG_ERROR(bad value ${enableval} for --enable-netbsd-atomic-ops) ;;
|
||||
esac
|
||||
],
|
||||
[atomic_netbsd_helpers=auto])
|
||||
|
||||
AC_MSG_CHECKING([target operating system])
|
||||
case $host in
|
||||
*-*-linux*)
|
||||
AC_MSG_RESULT([linux])
|
||||
pulse_target_os=linux
|
||||
;;
|
||||
*-*-netbsd*)
|
||||
AC_MSG_RESULT([netbsd])
|
||||
pulse_target_os=netbsd
|
||||
;;
|
||||
*)
|
||||
AC_MSG_RESULT([unknown])
|
||||
pulse_target_os=unknown
|
||||
|
|
@ -195,7 +210,13 @@ else
|
|||
fi
|
||||
;;
|
||||
*)
|
||||
if test "x$pulse_target_os" = "xnetbsd" && test "x$atomic_netbsd_helpers" = "xyes"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE_UNQUOTED(NETBSD_ATOMIC_OPS, 1, [netbsd implementation])
|
||||
need_libatomic_ops=no
|
||||
else
|
||||
AC_MSG_RESULT([unknown])
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
|
@ -275,6 +296,9 @@ AC_CHECK_HEADERS([sys/filio.h])
|
|||
# Windows
|
||||
AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h])
|
||||
|
||||
# NetBSD
|
||||
AC_CHECK_HEADERS([sys/atomic.h])
|
||||
|
||||
# Other
|
||||
AC_CHECK_HEADERS([sys/ioctl.h])
|
||||
AC_CHECK_HEADERS([byteswap.h])
|
||||
|
|
|
|||
|
|
@ -107,6 +107,79 @@ static inline pa_bool_t pa_atomic_ptr_cmpxchg(pa_atomic_ptr_t *a, void *old_p, v
|
|||
return __sync_bool_compare_and_swap(&a->value, (long) old_p, (long) new_p);
|
||||
}
|
||||
|
||||
#elif defined(__NetBSD__) && defined(HAVE_SYS_ATOMIC_H)
|
||||
|
||||
/* NetBSD 5.0+ atomic_ops(3) implementation */
|
||||
|
||||
#include <sys/atomic.h>
|
||||
|
||||
typedef struct pa_atomic {
|
||||
volatile unsigned int value;
|
||||
} pa_atomic_t;
|
||||
|
||||
#define PA_ATOMIC_INIT(v) { .value = (unsigned int) (v) }
|
||||
|
||||
static inline int pa_atomic_load(const pa_atomic_t *a) {
|
||||
membar_sync();
|
||||
return (int) a->value;
|
||||
}
|
||||
|
||||
static inline void pa_atomic_store(pa_atomic_t *a, int i) {
|
||||
a->value = (unsigned int) i;
|
||||
membar_sync();
|
||||
}
|
||||
|
||||
/* Returns the previously set value */
|
||||
static inline int pa_atomic_add(pa_atomic_t *a, int i) {
|
||||
int nv = (int) atomic_add_int_nv(&a->value, i);
|
||||
return nv - i;
|
||||
}
|
||||
|
||||
/* Returns the previously set value */
|
||||
static inline int pa_atomic_sub(pa_atomic_t *a, int i) {
|
||||
int nv = (int) atomic_add_int_nv(&a->value, -i);
|
||||
return nv + i;
|
||||
}
|
||||
|
||||
/* Returns the previously set value */
|
||||
static inline int pa_atomic_inc(pa_atomic_t *a) {
|
||||
int nv = (int) atomic_inc_uint_nv(&a->value);
|
||||
return nv - 1;
|
||||
}
|
||||
|
||||
/* Returns the previously set value */
|
||||
static inline int pa_atomic_dec(pa_atomic_t *a) {
|
||||
int nv = (int) atomic_dec_uint_nv(&a->value);
|
||||
return nv + 1;
|
||||
}
|
||||
|
||||
/* Returns TRUE when the operation was successful. */
|
||||
static inline pa_bool_t pa_atomic_cmpxchg(pa_atomic_t *a, int old_i, int new_i) {
|
||||
unsigned int r = atomic_cas_uint(&a->value, (unsigned int) old_i, (unsigned int) new_i);
|
||||
return (int) r == old_i;
|
||||
}
|
||||
|
||||
typedef struct pa_atomic_ptr {
|
||||
volatile void *value;
|
||||
} pa_atomic_ptr_t;
|
||||
|
||||
#define PA_ATOMIC_PTR_INIT(v) { .value = (v) }
|
||||
|
||||
static inline void* pa_atomic_ptr_load(const pa_atomic_ptr_t *a) {
|
||||
membar_sync();
|
||||
return (void *) a->value;
|
||||
}
|
||||
|
||||
static inline void pa_atomic_ptr_store(pa_atomic_ptr_t *a, void *p) {
|
||||
a->value = p;
|
||||
membar_sync();
|
||||
}
|
||||
|
||||
static inline pa_bool_t pa_atomic_ptr_cmpxchg(pa_atomic_ptr_t *a, void *old_p, void* new_p) {
|
||||
void *r = atomic_cas_ptr(&a->value, old_p, new_p);
|
||||
return r == old_p;
|
||||
}
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__amd64__) || defined(__x86_64__))
|
||||
|
||||
#warn "The native atomic operations implementation for AMD64 has not been tested thoroughly. libatomic_ops is known to not work properly on AMD64 and your gcc version is too old for the gcc-builtin atomic ops support. You have three options now: test the native atomic operations implementation for AMD64, fix libatomic_ops, or upgrade your GCC."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue