OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/gnu-old/gcc-4.2.2/libgomp/config/linux
    from Rev 154 to Rev 816
    Reverse comparison

Rev 154 → Rev 816

/powerpc/futex.h
0,0 → 1,70
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* Provide target-specific access to the futex system call. */
 
#include <sys/syscall.h>
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
 
static inline void
sys_futex0 (int *addr, int op, int val)
{
register long int r0 __asm__ ("r0");
register long int r3 __asm__ ("r3");
register long int r4 __asm__ ("r4");
register long int r5 __asm__ ("r5");
register long int r6 __asm__ ("r6");
 
r0 = SYS_futex;
r3 = (long) addr;
r4 = op;
r5 = val;
r6 = 0;
 
/* ??? The powerpc64 sysdep.h file clobbers ctr; the powerpc32 sysdep.h
doesn't. It doesn't much matter for us. In the interest of unity,
go ahead and clobber it always. */
 
__asm volatile ("sc"
: "=r"(r0), "=r"(r3), "=r"(r4), "=r"(r5), "=r"(r6)
: "r"(r0), "r"(r3), "r"(r4), "r"(r5), "r"(r6)
: "r7", "r8", "r9", "r10", "r11", "r12",
"cr0", "ctr", "memory");
}
 
static inline void
futex_wait (int *addr, int val)
{
sys_futex0 (addr, FUTEX_WAIT, val);
}
 
static inline void
futex_wake (int *addr, int count)
{
sys_futex0 (addr, FUTEX_WAKE, count);
}
/ia64/futex.h
0,0 → 1,71
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* Provide target-specific access to the futex system call. */
 
#include <sys/syscall.h>
 
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
 
 
static inline void
sys_futex0(int *addr, int op, int val)
{
register long out0 asm ("out0") = (long) addr;
register long out1 asm ("out1") = op;
register long out2 asm ("out2") = val;
register long out3 asm ("out3") = 0;
register long r15 asm ("r15") = SYS_futex;
 
__asm __volatile ("break 0x100000"
: "=r"(r15), "=r"(out0), "=r"(out1), "=r"(out2), "=r"(out3)
: "r"(r15), "r"(out0), "r"(out1), "r"(out2), "r"(out3)
: "memory", "r8", "r10", "out4", "out5", "out6", "out7",
/* Non-stacked integer registers, minus r8, r10, r15. */
"r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18",
"r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27",
"r28", "r29", "r30", "r31",
/* Predicate registers. */
"p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
/* Non-rotating fp registers. */
"f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
/* Branch registers. */
"b6");
}
 
static inline void
futex_wait (int *addr, int val)
{
sys_futex0 (addr, FUTEX_WAIT, val);
}
 
static inline void
futex_wake (int *addr, int count)
{
sys_futex0 (addr, FUTEX_WAKE, count);
}
/mutex.c
0,0 → 1,52
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of a mutex synchronization
mechanism for libgomp. This type is private to the library. This
implementation uses atomic instructions and the futex syscall. */
 
#include "libgomp.h"
#include "futex.h"
 
 
void
gomp_mutex_lock_slow (gomp_mutex_t *mutex)
{
do
{
int oldval = __sync_val_compare_and_swap (mutex, 1, 2);
if (oldval != 0)
futex_wait (mutex, 2);
}
while (!__sync_bool_compare_and_swap (mutex, 0, 2));
}
 
void
gomp_mutex_unlock_slow (gomp_mutex_t *mutex)
{
futex_wake (mutex, 1);
}
/alpha/futex.h
0,0 → 1,76
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* Provide target-specific access to the futex system call. */
 
#ifndef SYS_futex
#define SYS_futex 394
#endif
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
 
 
static inline void
futex_wait (int *addr, int val)
{
register long sc_0 __asm__("$0");
register long sc_16 __asm__("$16");
register long sc_17 __asm__("$17");
register long sc_18 __asm__("$18");
register long sc_19 __asm__("$19");
 
sc_0 = SYS_futex;
sc_16 = (long) addr;
sc_17 = FUTEX_WAIT;
sc_18 = val;
sc_19 = 0;
__asm volatile ("callsys"
: "=r" (sc_0), "=r"(sc_19)
: "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18), "1"(sc_19)
: "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",
"$22", "$23", "$24", "$25", "$27", "$28", "memory");
}
 
static inline void
futex_wake (int *addr, int count)
{
register long sc_0 __asm__("$0");
register long sc_16 __asm__("$16");
register long sc_17 __asm__("$17");
register long sc_18 __asm__("$18");
register long sc_19 __asm__("$19");
 
sc_0 = SYS_futex;
sc_16 = (long) addr;
sc_17 = FUTEX_WAKE;
sc_18 = count;
__asm volatile ("callsys"
: "=r" (sc_0), "=r"(sc_19)
: "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18)
: "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",
"$22", "$23", "$24", "$25", "$27", "$28", "memory");
}
/bar.c
0,0 → 1,64
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of a barrier synchronization
mechanism for libgomp. This type is private to the library. This
implementation uses atomic instructions and the futex syscall. */
 
#include "libgomp.h"
#include "futex.h"
#include <limits.h>
 
 
void
gomp_barrier_wait_end (gomp_barrier_t *bar, bool last)
{
if (last)
{
bar->generation++;
futex_wake (&bar->generation, INT_MAX);
}
else
{
unsigned int generation = bar->generation;
 
gomp_mutex_unlock (&bar->mutex);
 
do
futex_wait (&bar->generation, generation);
while (bar->generation == generation);
}
 
if (__sync_add_and_fetch (&bar->arrived, -1) == 0)
gomp_mutex_unlock (&bar->mutex);
}
 
void
gomp_barrier_wait (gomp_barrier_t *barrier)
{
gomp_barrier_wait_end (barrier, gomp_barrier_wait_start (barrier));
}
/sem.c
0,0 → 1,65
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of a semaphore synchronization
mechanism for libgomp. This type is private to the library. This
implementation uses atomic instructions and the futex syscall. */
 
#include "libgomp.h"
#include "futex.h"
 
 
void
gomp_sem_wait_slow (gomp_sem_t *sem)
{
while (1)
{
int val = __sync_val_compare_and_swap (sem, 0, -1);
if (val > 0)
{
if (__sync_bool_compare_and_swap (sem, val, val - 1))
return;
}
futex_wait (sem, -1);
}
}
 
void
gomp_sem_post_slow (gomp_sem_t *sem)
{
int old, tmp = *sem, wake;
 
do
{
old = tmp;
wake = old > 0 ? old + 1 : 1;
tmp = __sync_val_compare_and_swap (sem, old, wake);
}
while (old != tmp);
 
futex_wake (sem, wake);
}
/x86/futex.h
0,0 → 1,110
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* Provide target-specific access to the futex system call. */
 
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
 
#ifdef __LP64__
# ifndef SYS_futex
# define SYS_futex 202
# endif
 
static inline void
futex_wait (int *addr, int val)
{
register long r10 __asm__("%r10") = 0;
long res;
 
__asm volatile ("syscall"
: "=a" (res)
: "0"(SYS_futex), "D" (addr), "S"(FUTEX_WAIT),
"d"(val), "r"(r10)
: "r11", "rcx", "memory");
}
 
static inline void
futex_wake (int *addr, int count)
{
long res;
 
__asm volatile ("syscall"
: "=a" (res)
: "0"(SYS_futex), "D" (addr), "S"(FUTEX_WAKE), "d"(count)
: "r11", "rcx", "memory");
}
#else
# ifndef SYS_futex
# define SYS_futex 240
# endif
 
# ifdef __PIC__
 
static inline void
sys_futex0 (int *addr, int op, int val)
{
long res;
 
__asm volatile ("xchgl\t%%ebx, %2\n\t"
"int\t$0x80\n\t"
"xchgl\t%%ebx, %2"
: "=a" (res)
: "0"(SYS_futex), "r" (addr), "c"(op),
"d"(val), "S"(0)
: "memory");
}
 
# else
 
static inline void
sys_futex0 (int *addr, int op, int val)
{
long res;
 
__asm volatile ("int $0x80"
: "=a" (res)
: "0"(SYS_futex), "b" (addr), "c"(op),
"d"(val), "S"(0)
: "memory");
}
 
# endif /* __PIC__ */
 
static inline void
futex_wait (int *addr, int val)
{
sys_futex0 (addr, FUTEX_WAIT, val);
}
 
static inline void
futex_wake (int *addr, int count)
{
sys_futex0 (addr, FUTEX_WAKE, count);
}
 
#endif /* __LP64__ */
/omp-lock.h
0,0 → 1,10
/* This header is used during the build process to find the size and
alignment of the public OpenMP locks, so that we can export data
structures without polluting the namespace.
 
When using the Linux futex primitive, non-recursive locks require
only one int. Recursive locks require we identify the owning thread
and so require two ints. */
 
typedef int omp_lock_t;
typedef struct { int owner, count; } omp_nest_lock_t;
/mutex.h
0,0 → 1,63
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of a mutex synchronization
mechanism for libgomp. This type is private to the library. This
implementation uses atomic instructions and the futex syscall. */
 
#ifndef GOMP_MUTEX_H
#define GOMP_MUTEX_H 1
 
typedef int gomp_mutex_t;
 
#define GOMP_MUTEX_INIT_0 1
 
static inline void gomp_mutex_init (gomp_mutex_t *mutex)
{
*mutex = 0;
}
 
extern void gomp_mutex_lock_slow (gomp_mutex_t *mutex);
static inline void gomp_mutex_lock (gomp_mutex_t *mutex)
{
if (!__sync_bool_compare_and_swap (mutex, 0, 1))
gomp_mutex_lock_slow (mutex);
}
 
extern void gomp_mutex_unlock_slow (gomp_mutex_t *mutex);
static inline void gomp_mutex_unlock (gomp_mutex_t *mutex)
{
int val = __sync_lock_test_and_set (mutex, 0);
if (__builtin_expect (val > 1, 0))
gomp_mutex_unlock_slow (mutex);
}
 
static inline void gomp_mutex_destroy (gomp_mutex_t *mutex)
{
}
 
#endif /* GOMP_MUTEX_H */
/sparc/futex.h
0,0 → 1,80
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Jakub Jelinek <jakub@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* Provide target-specific access to the futex system call. */
 
#include <sys/syscall.h>
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
 
static inline void
sys_futex0 (int *addr, int op, int val)
{
register long int g1 __asm__ ("g1");
register long int o0 __asm__ ("o0");
register long int o1 __asm__ ("o1");
register long int o2 __asm__ ("o2");
register long int o3 __asm__ ("o3");
 
g1 = SYS_futex;
o0 = (long) addr;
o1 = op;
o2 = val;
o3 = 0;
 
#ifdef __arch64__
# define SYSCALL_STRING "ta\t0x6d"
#else
# define SYSCALL_STRING "ta\t0x10"
#endif
 
__asm volatile (SYSCALL_STRING
: "=r" (g1), "=r" (o0)
: "0" (g1), "1" (o0), "r" (o1), "r" (o2), "r" (o3)
: "g2", "g3", "g4", "g5", "g6",
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
#ifdef __arch64__
"f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
"f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
#endif
"cc", "memory");
}
 
static inline void
futex_wait (int *addr, int val)
{
sys_futex0 (addr, FUTEX_WAIT, val);
}
 
static inline void
futex_wake (int *addr, int count)
{
sys_futex0 (addr, FUTEX_WAKE, count);
}
/lock.c
0,0 → 1,182
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of the public OpenMP locking
primitives. This implementation uses atomic instructions and the futex
syscall. */
 
#include "libgomp.h"
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include "futex.h"
 
 
/* The internal gomp_mutex_t and the external non-recursive omp_lock_t
have the same form. Re-use it. */
 
void
omp_init_lock (omp_lock_t *lock)
{
gomp_mutex_init (lock);
}
 
void
omp_destroy_lock (omp_lock_t *lock)
{
gomp_mutex_destroy (lock);
}
 
void
omp_set_lock (omp_lock_t *lock)
{
gomp_mutex_lock (lock);
}
 
void
omp_unset_lock (omp_lock_t *lock)
{
gomp_mutex_unlock (lock);
}
 
int
omp_test_lock (omp_lock_t *lock)
{
return __sync_bool_compare_and_swap (lock, 0, 1);
}
 
/* The external recursive omp_nest_lock_t form requires additional work. */
 
/* We need an integer to uniquely identify this thread. Most generally
this is the thread's TID, which ideally we'd get this straight from
the TLS block where glibc keeps it. Unfortunately, we can't get at
that directly.
 
If we don't support (or have disabled) TLS, one function call is as
good (or bad) as any other. Use the syscall all the time.
 
On an ILP32 system (defined here as not LP64), we can make do with
any thread-local pointer. Ideally we'd use the TLS base address,
since that requires the least amount of arithmetic, but that's not
always available directly. Make do with the gomp_thread pointer
since it's handy. */
 
#if !defined (HAVE_TLS)
static inline int gomp_tid (void)
{
return syscall (SYS_gettid);
}
#elif !defined(__LP64__)
static inline int gomp_tid (void)
{
return (int) gomp_thread ();
}
#else
static __thread int tid_cache;
static inline int gomp_tid (void)
{
int tid = tid_cache;
if (__builtin_expect (tid == 0, 0))
tid_cache = tid = syscall (SYS_gettid);
return tid;
}
#endif
 
 
void
omp_init_nest_lock (omp_nest_lock_t *lock)
{
memset (lock, 0, sizeof (lock));
}
 
void
omp_destroy_nest_lock (omp_nest_lock_t *lock)
{
}
 
void
omp_set_nest_lock (omp_nest_lock_t *lock)
{
int otid, tid = gomp_tid ();
 
while (1)
{
otid = __sync_val_compare_and_swap (&lock->owner, 0, tid);
if (otid == 0)
{
lock->count = 1;
return;
}
if (otid == tid)
{
lock->count++;
return;
}
 
futex_wait (&lock->owner, otid);
}
}
 
void
omp_unset_nest_lock (omp_nest_lock_t *lock)
{
/* ??? Validate that we own the lock here. */
 
if (--lock->count == 0)
{
__sync_lock_release (&lock->owner);
futex_wake (&lock->owner, 1);
}
}
 
int
omp_test_nest_lock (omp_nest_lock_t *lock)
{
int otid, tid = gomp_tid ();
 
otid = __sync_val_compare_and_swap (&lock->owner, 0, tid);
if (otid == 0)
{
lock->count = 1;
return 1;
}
if (otid == tid)
return ++lock->count;
 
return 0;
}
 
ialias (omp_init_lock)
ialias (omp_init_nest_lock)
ialias (omp_destroy_lock)
ialias (omp_destroy_nest_lock)
ialias (omp_set_lock)
ialias (omp_set_nest_lock)
ialias (omp_unset_lock)
ialias (omp_unset_nest_lock)
ialias (omp_test_lock)
ialias (omp_test_nest_lock)
/bar.h
0,0 → 1,75
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of a barrier synchronization
mechanism for libgomp. This type is private to the library. This
implementation uses atomic instructions and the futex syscall. */
 
#ifndef GOMP_BARRIER_H
#define GOMP_BARRIER_H 1
 
#include "mutex.h"
 
typedef struct
{
gomp_mutex_t mutex;
unsigned total;
unsigned arrived;
int generation;
} gomp_barrier_t;
 
static inline void gomp_barrier_init (gomp_barrier_t *bar, unsigned count)
{
gomp_mutex_init (&bar->mutex);
bar->total = count;
bar->arrived = 0;
bar->generation = 0;
}
 
static inline void gomp_barrier_reinit (gomp_barrier_t *bar, unsigned count)
{
gomp_mutex_lock (&bar->mutex);
bar->total = count;
gomp_mutex_unlock (&bar->mutex);
}
 
static inline void gomp_barrier_destroy (gomp_barrier_t *bar)
{
/* Before destroying, make sure all threads have left the barrier. */
gomp_mutex_lock (&bar->mutex);
}
 
extern void gomp_barrier_wait (gomp_barrier_t *);
extern void gomp_barrier_wait_end (gomp_barrier_t *, bool);
 
static inline bool gomp_barrier_wait_start (gomp_barrier_t *bar)
{
gomp_mutex_lock (&bar->mutex);
return ++bar->arrived == bar->total;
}
 
#endif /* GOMP_BARRIER_H */
/sem.h
0,0 → 1,60
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* This is a Linux specific implementation of a semaphore synchronization
mechanism for libgomp. This type is private to the library. This
implementation uses atomic instructions and the futex syscall. */
 
#ifndef GOMP_SEM_H
#define GOMP_SEM_H 1
 
typedef int gomp_sem_t;
 
static inline void gomp_sem_init (gomp_sem_t *sem, int value)
{
*sem = value;
}
 
extern void gomp_sem_wait_slow (gomp_sem_t *);
static inline void gomp_sem_wait (gomp_sem_t *sem)
{
if (!__sync_bool_compare_and_swap (sem, 1, 0))
gomp_sem_wait_slow (sem);
}
 
extern void gomp_sem_post_slow (gomp_sem_t *);
static inline void gomp_sem_post (gomp_sem_t *sem)
{
if (!__sync_bool_compare_and_swap (sem, 0, 1))
gomp_sem_post_slow (sem);
}
 
static inline void gomp_sem_destroy (gomp_sem_t *sem)
{
}
 
#endif /* GOMP_SEM_H */
/s390/futex.h
0,0 → 1,64
/* Copyright (C) 2005 Free Software Foundation, Inc.
Contributed by Jakub Jelinek <jakub@redhat.com>.
 
This file is part of the GNU OpenMP Library (libgomp).
 
Libgomp 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.
 
Libgomp 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 libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
 
/* As a special exception, if you link this library with other files, some
of which are compiled with GCC, to produce an executable, this library
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. */
 
/* Provide target-specific access to the futex system call. */
 
#include <sys/syscall.h>
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
 
static inline void
sys_futex0 (int *addr, int op, int val)
{
register long int gpr2 __asm__ ("2");
register long int gpr3 __asm__ ("3");
register long int gpr4 __asm__ ("4");
register long int gpr5 __asm__ ("5");
 
gpr2 = (long) addr;
gpr3 = op;
gpr4 = val;
gpr5 = 0;
 
__asm volatile ("svc %b1"
: "=d" (gpr2)
: "i" (SYS_futex),
"0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
: "memory");
}
 
static inline void
futex_wait (int *addr, int val)
{
sys_futex0 (addr, FUTEX_WAIT, val);
}
 
static inline void
futex_wake (int *addr, int count)
{
sys_futex0 (addr, FUTEX_WAKE, count);
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.