Browse Source

Use generic atomic functions

Use atomic_fetch_add from C11's stdatomic if available or fallback to
GCC's __atomic functions.

Remove atomic_add because is can trivially be implemented by calling
exchange_and_add instead.
tags/0.126.0
James Cowgill 5 years ago
parent
commit
eed8a97b2f
3 changed files with 22 additions and 15 deletions
  1. +20
    -13
      include/atomicity.h
  2. +1
    -1
      include/internal.h
  3. +1
    -1
      libjack/messagebuffer.c

+ 20
- 13
include/atomicity.h View File

@@ -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__ */

+ 1
- 1
include/internal.h View File

@@ -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>


+ 1
- 1
libjack/messagebuffer.c View File

@@ -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);
}
}



Loading…
Cancel
Save