summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Coelho <falktx@falktx.com>2017-01-16 10:48:35 +0100
committerGitHub <noreply@github.com>2017-01-16 10:48:35 +0100
commit44e23985f7f17c00609301aba59d74b15bf91c8c (patch)
tree2e329328d3fd5675047a9c3d8414a747df649fde
parent90f9dd39b0a08802f05e2f09622197f922210c81 (diff)
parentddc60b08e2fc5a051a131fb468c2f5343bf9f335 (diff)
downloadjack1-44e23985f7f17c00609301aba59d74b15bf91c8c.tar.gz
Merge pull request #62 from jcowgill/atomics-cleanup
Atomics cleanup
-rw-r--r--config/Makefile.am2
-rw-r--r--config/cpu/Makefile.am2
-rw-r--r--config/cpu/generic/Makefile.am3
-rw-r--r--config/cpu/generic/atomicity.h39
-rw-r--r--config/cpu/i386/Makefile.am3
-rw-r--r--config/cpu/i386/atomicity.h53
-rw-r--r--config/cpu/powerpc/Makefile.am3
-rw-r--r--config/cpu/powerpc/atomicity.h80
-rw-r--r--config/sysdeps/Makefile.am1
-rw-r--r--config/sysdeps/atomicity.h24
-rw-r--r--configure.ac4
-rw-r--r--doc/porting.dox19
-rw-r--r--include/atomicity.h33
-rw-r--r--include/internal.h2
-rw-r--r--libjack/messagebuffer.c2
15 files changed, 23 insertions, 247 deletions
diff --git a/config/Makefile.am b/config/Makefile.am
index d608932..7f06fc8 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -1,7 +1,7 @@
# We don't actually build anything in the `cpu' and `os'
# subdirectories.
-DIST_SUBDIRS = cpu os sysdeps
+DIST_SUBDIRS = os sysdeps
EXTRA_DIST = depcomp
MAINTAINERCLEANFILES = Makefile.in config.guess config.sub \
diff --git a/config/cpu/Makefile.am b/config/cpu/Makefile.am
deleted file mode 100644
index 93dde0d..0000000
--- a/config/cpu/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-MAINTAINERCLEANFILES = Makefile.in
-DIST_SUBDIRS = generic i386 powerpc
diff --git a/config/cpu/generic/Makefile.am b/config/cpu/generic/Makefile.am
deleted file mode 100644
index 166d93d..0000000
--- a/config/cpu/generic/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-MAINTAINERCLEANFILES = Makefile.in
-noinst_HEADERS = atomicity.h
-
diff --git a/config/cpu/generic/atomicity.h b/config/cpu/generic/atomicity.h
deleted file mode 100644
index b781c44..0000000
--- a/config/cpu/generic/atomicity.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Low-level functions for atomic operations. Stub version.
- Copyright (C) 1997,2001 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#ifndef _ATOMICITY_H
-#define _ATOMICITY_H 1
-
-typedef int _Atomic_word;
-
-static inline _Atomic_word
-__attribute__ ((__unused__))
-__exchange_and_add (volatile _Atomic_word* mem, int val)
-{
- return __sync_fetch_and_add (mem, val);
-}
-
-static inline void
-__attribute__ ((__unused__))
-__atomic_add (volatile _Atomic_word* mem, int val)
-{
- __sync_add_and_fetch (mem, val);
-}
-
-#endif /* atomicity.h */
diff --git a/config/cpu/i386/Makefile.am b/config/cpu/i386/Makefile.am
deleted file mode 100644
index 166d93d..0000000
--- a/config/cpu/i386/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-MAINTAINERCLEANFILES = Makefile.in
-noinst_HEADERS = atomicity.h
-
diff --git a/config/cpu/i386/atomicity.h b/config/cpu/i386/atomicity.h
deleted file mode 100644
index b9cad70..0000000
--- a/config/cpu/i386/atomicity.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library 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 Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
-
-typedef int _Atomic_word;
-
-static inline _Atomic_word
-__attribute__ ((__unused__))
-__exchange_and_add (volatile _Atomic_word* __mem, int __val)
-{
- register _Atomic_word __result;
-
- __asm__ __volatile__ ("lock; xaddl %0,%1"
- : "=r" (__result), "=m" (*__mem)
- : "0" (__val), "m" (*__mem));
- return __result;
-}
-
-static inline void
-__attribute__ ((__unused__))
-__atomic_add (volatile _Atomic_word* __mem, int __val)
-{
- __asm__ __volatile__ ("lock; addl %1,%0"
- : "=m" (*__mem) : "ir" (__val), "m" (*__mem));
-}
-
-#endif /* atomicity.h */
diff --git a/config/cpu/powerpc/Makefile.am b/config/cpu/powerpc/Makefile.am
deleted file mode 100644
index 166d93d..0000000
--- a/config/cpu/powerpc/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-MAINTAINERCLEANFILES = Makefile.in
-noinst_HEADERS = atomicity.h
-
diff --git a/config/cpu/powerpc/atomicity.h b/config/cpu/powerpc/atomicity.h
deleted file mode 100644
index 5a74a65..0000000
--- a/config/cpu/powerpc/atomicity.h
+++ /dev/null
@@ -1,80 +0,0 @@
-// Low-level functions for atomic operations: PowerPC version -*- C++ -*-
-
-// Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library 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 Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
-
-#ifdef __PPC405__
-#define _STWCX "sync \n\tstwcx. "
-#else
-#define _STWCX "stwcx. "
-#endif
-
-typedef int _Atomic_word;
-
-static inline _Atomic_word
-__attribute__ ((__unused__))
-__exchange_and_add (volatile _Atomic_word* __mem, int __val)
-{
- _Atomic_word __tmp, __res;
-
- __asm__ __volatile__ (
- "/* Inline exchange & add */\n"
- "0:\t"
- "lwarx %0,0,%3 \n\t"
- "add%I4 %1,%0,%4 \n\t"
- _STWCX " %1,0,%3 \n\t"
- "bne- 0b \n\t"
- "/* End exchange & add */"
- : "=&b" (__res), "=&r" (__tmp), "=m" (*__mem)
- : "r" (__mem), "Ir" (__val), "m" (*__mem)
- : "cr0");
- return __res;
-}
-
-static inline void
-__attribute__ ((__unused__))
-__atomic_add (volatile _Atomic_word* __mem, int __val)
-{
- _Atomic_word __tmp;
-
- __asm__ __volatile__ (
- "/* Inline atomic add */\n"
- "0:\t"
- "lwarx %0,0,%2 \n\t"
- "add%I3 %0,%0,%3 \n\t"
- _STWCX " %0,0,%2 \n\t"
- "bne- 0b \n\t"
- "/* End atomic add */"
- : "=&b" (__tmp), "=m" (*__mem)
- : "r" (__mem), "Ir" (__val), "m" (*__mem)
- : "cr0");
-}
-
-#endif /* atomicity.h */
diff --git a/config/sysdeps/Makefile.am b/config/sysdeps/Makefile.am
index ca6d438..db98e58 100644
--- a/config/sysdeps/Makefile.am
+++ b/config/sysdeps/Makefile.am
@@ -7,7 +7,6 @@ MAINTAINERCLEANFILES = Makefile.in
noinst_HEADERS = \
systemtest.c \
sanitycheck.c \
- atomicity.h \
getopt.h \
ipc.h \
mach_port.h \
diff --git a/config/sysdeps/atomicity.h b/config/sysdeps/atomicity.h
deleted file mode 100644
index ae86b12..0000000
--- a/config/sysdeps/atomicity.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef _jack_sysdep_atomicity_h_
-#define _jack_sysdep_atomicity_h_
-
-#if defined(__i386__)
-
-#include <config/cpu/i386/atomicity.h>
-
-#elif defined(__x86_64)
-
-/* x86_64 can use rdtsc just like i[456]86 */
-
-#include <config/cpu/i386/atomicity.h>
-
-#elif defined(__powerpc__) || defined(__ppc__) /* linux and OSX use different tokens */
-
-#include <config/cpu/powerpc/atomicity.h>
-
-#else
-
-#include <config/cpu/generic/atomicity.h>
-
-#endif /* processor selection */
-
-#endif /* _jack_sysdep_atomicity_h_ */
diff --git a/configure.ac b/configure.ac
index 4c0e910..9c7cbf1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -964,10 +964,6 @@ AM_CONDITIONAL(HAVE_ZITA_BRIDGE_DEPS, $HAVE_ZITA_BRIDGE_DEPS)
AC_OUTPUT(
Makefile
config/Makefile
-config/cpu/Makefile
-config/cpu/generic/Makefile
-config/cpu/i386/Makefile
-config/cpu/powerpc/Makefile
config/os/Makefile
config/os/generic/Makefile
config/os/gnu-linux/Makefile
diff --git a/doc/porting.dox b/doc/porting.dox
index 011e2e9..d9c4633 100644
--- a/doc/porting.dox
+++ b/doc/porting.dox
@@ -88,25 +88,6 @@ Be sure to place any generic implementation alternative in the @c
\#else or use an @c \#ifndef, so no other code needs to know your
conditional labels.
-@section portcpu Processor Dependencies
-
-JACK uses some low-level machine operations for thread-safe updates to
-shared memory. A low-level implementation of @c <sysdeps/atomicity.h>
-is provided for every target processor architecture. There is also a
-generic implementation using POSIX spin locks, but that is not a good
-enough solution for serious use.
-
-The GCC package provides versions that work on most modern hardware.
-We've tried to keep things as close to the original as possible, while
-removing a bunch of os-specific files that didn't seem relevant. A
-primary goal has been to avoid changing the CPU-dependent @c
-<sysdeps/atomicity.h> headers.
-
-The relevant GCC documentation provides some helpful background,
-especially the @c atomicity.h discussion at
-<http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html>.
-
-
@section portissues Issues Not Addressed
- Cross-compilation has not been tested, or even thought through in
diff --git a/include/atomicity.h b/include/atomicity.h
index edf4ada..4c935c5 100644
--- a/include/atomicity.h
+++ b/include/atomicity.h
@@ -20,19 +20,26 @@
#ifndef __jack_atomicity_h__
#define __jack_atomicity_h__
-/*
- * Interface with various machine-dependent headers derived from the
- * gcc/libstdc++.v3 sources. We try to modify the GCC sources as
- * little as possible. The following include is resolved using the
- * config/configure.hosts mechanism. It will use an OS-dependent
- * version if available, otherwise the one for this CPU. Some of
- * these files might not work with older GCC compilers.
- */
-#include <sysdeps/atomicity.h>
+#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
+
+#include <stdatomic.h>
+
+typedef atomic_int _Atomic_word;
+
+static inline int exchange_and_add(volatile _Atomic_word* obj, int value)
+{
+ return atomic_fetch_add_explicit(obj, value, memory_order_relaxed);
+}
+
+#else
+
+typedef int _Atomic_word;
+
+static inline int exchange_and_add(volatile _Atomic_word* obj, int value)
+{
+ return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED);
+}
-/* These functions are defined for each platform. The C++ library
- * function names start with "__" to avoid namespace pollution. */
-#define exchange_and_add __exchange_and_add
-#define atomic_add __atomic_add
+#endif
#endif /* __jack_atomicity_h__ */
diff --git a/include/internal.h b/include/internal.h
index e3574bd..396b456 100644
--- a/include/internal.h
+++ b/include/internal.h
@@ -60,7 +60,7 @@ void jack_set_clock_source (jack_timer_type_t);
const char* jack_clock_source_name (jack_timer_type_t);
#include <sysdeps/time.h>
-#include <sysdeps/atomicity.h>
+#include "atomicity.h"
#ifdef JACK_USE_MACH_THREADS
#include <sysdeps/mach_port.h>
diff --git a/libjack/messagebuffer.c b/libjack/messagebuffer.c
index 5f9541a..082f2f1 100644
--- a/libjack/messagebuffer.c
+++ b/libjack/messagebuffer.c
@@ -161,7 +161,7 @@ jack_messagebuffer_add (const char *fmt, ...)
pthread_cond_signal (&mb_ready_cond);
pthread_mutex_unlock (&mb_write_lock);
} else { /* lock collision */
- atomic_add (&mb_overruns, 1);
+ exchange_and_add (&mb_overruns, 1);
}
}