Skip to content

Commit 44e2398

Browse files
authored
Merge pull request #62 from jcowgill/atomics-cleanup
Atomics cleanup
2 parents 90f9dd3 + ddc60b0 commit 44e2398

15 files changed

+23
-247
lines changed

config/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# We don't actually build anything in the `cpu' and `os'
22
# subdirectories.
33

4-
DIST_SUBDIRS = cpu os sysdeps
4+
DIST_SUBDIRS = os sysdeps
55

66
EXTRA_DIST = depcomp
77
MAINTAINERCLEANFILES = Makefile.in config.guess config.sub \

config/cpu/Makefile.am

-2
This file was deleted.

config/cpu/generic/Makefile.am

-3
This file was deleted.

config/cpu/generic/atomicity.h

-39
This file was deleted.

config/cpu/i386/Makefile.am

-3
This file was deleted.

config/cpu/i386/atomicity.h

-53
This file was deleted.

config/cpu/powerpc/Makefile.am

-3
This file was deleted.

config/cpu/powerpc/atomicity.h

-80
This file was deleted.

config/sysdeps/Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ MAINTAINERCLEANFILES = Makefile.in
77
noinst_HEADERS = \
88
systemtest.c \
99
sanitycheck.c \
10-
atomicity.h \
1110
getopt.h \
1211
ipc.h \
1312
mach_port.h \

config/sysdeps/atomicity.h

-24
This file was deleted.

configure.ac

-4
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,6 @@ AM_CONDITIONAL(HAVE_ZITA_BRIDGE_DEPS, $HAVE_ZITA_BRIDGE_DEPS)
964964
AC_OUTPUT(
965965
Makefile
966966
config/Makefile
967-
config/cpu/Makefile
968-
config/cpu/generic/Makefile
969-
config/cpu/i386/Makefile
970-
config/cpu/powerpc/Makefile
971967
config/os/Makefile
972968
config/os/generic/Makefile
973969
config/os/gnu-linux/Makefile

doc/porting.dox

-19
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,6 @@ Be sure to place any generic implementation alternative in the @c
8888
\#else or use an @c \#ifndef, so no other code needs to know your
8989
conditional labels.
9090

91-
@section portcpu Processor Dependencies
92-
93-
JACK uses some low-level machine operations for thread-safe updates to
94-
shared memory. A low-level implementation of @c <sysdeps/atomicity.h>
95-
is provided for every target processor architecture. There is also a
96-
generic implementation using POSIX spin locks, but that is not a good
97-
enough solution for serious use.
98-
99-
The GCC package provides versions that work on most modern hardware.
100-
We've tried to keep things as close to the original as possible, while
101-
removing a bunch of os-specific files that didn't seem relevant. A
102-
primary goal has been to avoid changing the CPU-dependent @c
103-
<sysdeps/atomicity.h> headers.
104-
105-
The relevant GCC documentation provides some helpful background,
106-
especially the @c atomicity.h discussion at
107-
<http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html>.
108-
109-
11091
@section portissues Issues Not Addressed
11192

11293
- Cross-compilation has not been tested, or even thought through in

include/atomicity.h

+20-13
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@
2020
#ifndef __jack_atomicity_h__
2121
#define __jack_atomicity_h__
2222

23-
/*
24-
* Interface with various machine-dependent headers derived from the
25-
* gcc/libstdc++.v3 sources. We try to modify the GCC sources as
26-
* little as possible. The following include is resolved using the
27-
* config/configure.hosts mechanism. It will use an OS-dependent
28-
* version if available, otherwise the one for this CPU. Some of
29-
* these files might not work with older GCC compilers.
30-
*/
31-
#include <sysdeps/atomicity.h>
23+
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
24+
25+
#include <stdatomic.h>
26+
27+
typedef atomic_int _Atomic_word;
28+
29+
static inline int exchange_and_add(volatile _Atomic_word* obj, int value)
30+
{
31+
return atomic_fetch_add_explicit(obj, value, memory_order_relaxed);
32+
}
33+
34+
#else
35+
36+
typedef int _Atomic_word;
37+
38+
static inline int exchange_and_add(volatile _Atomic_word* obj, int value)
39+
{
40+
return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED);
41+
}
3242

33-
/* These functions are defined for each platform. The C++ library
34-
* function names start with "__" to avoid namespace pollution. */
35-
#define exchange_and_add __exchange_and_add
36-
#define atomic_add __atomic_add
43+
#endif
3744

3845
#endif /* __jack_atomicity_h__ */

include/internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void jack_set_clock_source (jack_timer_type_t);
6060
const char* jack_clock_source_name (jack_timer_type_t);
6161

6262
#include <sysdeps/time.h>
63-
#include <sysdeps/atomicity.h>
63+
#include "atomicity.h"
6464

6565
#ifdef JACK_USE_MACH_THREADS
6666
#include <sysdeps/mach_port.h>

libjack/messagebuffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ jack_messagebuffer_add (const char *fmt, ...)
161161
pthread_cond_signal (&mb_ready_cond);
162162
pthread_mutex_unlock (&mb_write_lock);
163163
} else { /* lock collision */
164-
atomic_add (&mb_overruns, 1);
164+
exchange_and_add (&mb_overruns, 1);
165165
}
166166
}
167167

0 commit comments

Comments
 (0)