| 1 |
735 |
jeremybenn |
/* Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
| 2 |
|
|
Contributed by ARM Ltd.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of the GNU OpenMP Library (libgomp).
|
| 5 |
|
|
|
| 6 |
|
|
Libgomp is free software; you can redistribute it and/or modify it
|
| 7 |
|
|
under the terms of the GNU General Public License as published by
|
| 8 |
|
|
the Free Software Foundation; either version 3, or (at your option)
|
| 9 |
|
|
any later version.
|
| 10 |
|
|
|
| 11 |
|
|
Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
|
| 12 |
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
| 13 |
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 14 |
|
|
more details.
|
| 15 |
|
|
|
| 16 |
|
|
Under Section 7 of GPL version 3, you are granted additional
|
| 17 |
|
|
permissions described in the GCC Runtime Library Exception, version
|
| 18 |
|
|
3.1, as published by the Free Software Foundation.
|
| 19 |
|
|
|
| 20 |
|
|
You should have received a copy of the GNU General Public License and
|
| 21 |
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
| 22 |
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
| 23 |
|
|
<http://www.gnu.org/licenses/>. */
|
| 24 |
|
|
|
| 25 |
|
|
/* Provide target-specific access to the futex system call. */
|
| 26 |
|
|
|
| 27 |
|
|
/* The include file hierachy above us (wait.h) has pushed visibility
|
| 28 |
|
|
hidden, this will be applied to prototypes with headers we include
|
| 29 |
|
|
with the effect that we cannot link against an external function
|
| 30 |
|
|
(syscall). The solution here is to push default visibility, include
|
| 31 |
|
|
our required headers then reinstante the original visibility. */
|
| 32 |
|
|
|
| 33 |
|
|
#pragma GCC visibility push(default)
|
| 34 |
|
|
|
| 35 |
|
|
#define _GNU_SOURCE
|
| 36 |
|
|
#include <unistd.h>
|
| 37 |
|
|
#include <sys/syscall.h>
|
| 38 |
|
|
|
| 39 |
|
|
#pragma GCC visibility pop
|
| 40 |
|
|
|
| 41 |
|
|
static inline void
|
| 42 |
|
|
futex_wait (int *addr, int val)
|
| 43 |
|
|
{
|
| 44 |
|
|
long err = syscall (SYS_futex, addr, gomp_futex_wait, val, NULL);
|
| 45 |
|
|
if (__builtin_expect (err == -ENOSYS, 0))
|
| 46 |
|
|
{
|
| 47 |
|
|
gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
|
| 48 |
|
|
gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
|
| 49 |
|
|
syscall (SYS_futex, addr, gomp_futex_wait, val, NULL);
|
| 50 |
|
|
}
|
| 51 |
|
|
}
|
| 52 |
|
|
|
| 53 |
|
|
static inline void
|
| 54 |
|
|
futex_wake (int *addr, int count)
|
| 55 |
|
|
{
|
| 56 |
|
|
long err = syscall (SYS_futex, addr, gomp_futex_wake, count);
|
| 57 |
|
|
if (__builtin_expect (err == -ENOSYS, 0))
|
| 58 |
|
|
{
|
| 59 |
|
|
gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
|
| 60 |
|
|
gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
|
| 61 |
|
|
syscall (SYS_futex, addr, gomp_futex_wake, count);
|
| 62 |
|
|
}
|
| 63 |
|
|
}
|
| 64 |
|
|
|
| 65 |
|
|
static inline void
|
| 66 |
|
|
cpu_relax (void)
|
| 67 |
|
|
{
|
| 68 |
|
|
__asm volatile ("" : : : "memory");
|
| 69 |
|
|
}
|