Browse Source

Merge pull request #62 from jcowgill/atomics-cleanup

Atomics cleanup
tags/0.126.0
Filipe Coelho GitHub 8 years ago
parent
commit
44e23985f7
15 changed files with 23 additions and 247 deletions
  1. +1
    -1
      config/Makefile.am
  2. +0
    -2
      config/cpu/Makefile.am
  3. +0
    -3
      config/cpu/generic/Makefile.am
  4. +0
    -39
      config/cpu/generic/atomicity.h
  5. +0
    -3
      config/cpu/i386/Makefile.am
  6. +0
    -53
      config/cpu/i386/atomicity.h
  7. +0
    -3
      config/cpu/powerpc/Makefile.am
  8. +0
    -80
      config/cpu/powerpc/atomicity.h
  9. +0
    -1
      config/sysdeps/Makefile.am
  10. +0
    -24
      config/sysdeps/atomicity.h
  11. +0
    -4
      configure.ac
  12. +0
    -19
      doc/porting.dox
  13. +20
    -13
      include/atomicity.h
  14. +1
    -1
      include/internal.h
  15. +1
    -1
      libjack/messagebuffer.c

+ 1
- 1
config/Makefile.am View File

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


+ 0
- 2
config/cpu/Makefile.am View File

@@ -1,2 +0,0 @@
MAINTAINERCLEANFILES = Makefile.in
DIST_SUBDIRS = generic i386 powerpc

+ 0
- 3
config/cpu/generic/Makefile.am View File

@@ -1,3 +0,0 @@
MAINTAINERCLEANFILES = Makefile.in
noinst_HEADERS = atomicity.h


+ 0
- 39
config/cpu/generic/atomicity.h View File

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

+ 0
- 3
config/cpu/i386/Makefile.am View File

@@ -1,3 +0,0 @@
MAINTAINERCLEANFILES = Makefile.in
noinst_HEADERS = atomicity.h


+ 0
- 53
config/cpu/i386/atomicity.h View File

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

+ 0
- 3
config/cpu/powerpc/Makefile.am View File

@@ -1,3 +0,0 @@
MAINTAINERCLEANFILES = Makefile.in
noinst_HEADERS = atomicity.h


+ 0
- 80
config/cpu/powerpc/atomicity.h View File

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

+ 0
- 1
config/sysdeps/Makefile.am View File

@@ -7,7 +7,6 @@ MAINTAINERCLEANFILES = Makefile.in
noinst_HEADERS = \
systemtest.c \
sanitycheck.c \
atomicity.h \
getopt.h \
ipc.h \
mach_port.h \


+ 0
- 24
config/sysdeps/atomicity.h View File

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

+ 0
- 4
configure.ac View File

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


+ 0
- 19
doc/porting.dox View File

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


+ 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