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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libgomp/] [config/] [linux/] [x86/] [futex.h] - Blame information for rev 273

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 273 jeremybenn
/* Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
2
   Contributed by Richard Henderson <rth@redhat.com>.
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
#ifdef __LP64__
28
# ifndef SYS_futex
29
#  define SYS_futex     202
30
# endif
31
 
32
static inline void
33
futex_wait (int *addr, int val)
34
{
35
  register long r10 __asm__("%r10");
36
  long res;
37
 
38
  r10 = 0;
39
  __asm volatile ("syscall"
40
                  : "=a" (res)
41
                  : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
42
                    "d" (val), "r" (r10)
43
                  : "r11", "rcx", "memory");
44
  if (__builtin_expect (res == -ENOSYS, 0))
45
    {
46
      gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
47
      gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
48
      r10 = 0;
49
      __asm volatile ("syscall"
50
                      : "=a" (res)
51
                      : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
52
                        "d" (val), "r" (r10)
53
                      : "r11", "rcx", "memory");
54
    }
55
}
56
 
57
static inline void
58
futex_wake (int *addr, int count)
59
{
60
  long res;
61
 
62
  __asm volatile ("syscall"
63
                  : "=a" (res)
64
                  : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake),
65
                    "d" (count)
66
                  : "r11", "rcx", "memory");
67
  if (__builtin_expect (res == -ENOSYS, 0))
68
    {
69
      gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
70
      gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
71
      __asm volatile ("syscall"
72
                      : "=a" (res)
73
                      : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake),
74
                        "d" (count)
75
                      : "r11", "rcx", "memory");
76
    }
77
}
78
#else
79
# ifndef SYS_futex
80
#  define SYS_futex     240
81
# endif
82
 
83
# ifdef __PIC__
84
 
85
static inline long
86
sys_futex0 (int *addr, int op, int val)
87
{
88
  long res;
89
 
90
  __asm volatile ("xchgl\t%%ebx, %2\n\t"
91
                  "int\t$0x80\n\t"
92
                  "xchgl\t%%ebx, %2"
93
                  : "=a" (res)
94
                  : "0"(SYS_futex), "r" (addr), "c"(op),
95
                    "d"(val), "S"(0)
96
                  : "memory");
97
  return res;
98
}
99
 
100
# else
101
 
102
static inline long
103
sys_futex0 (int *addr, int op, int val)
104
{
105
  long res;
106
 
107
  __asm volatile ("int $0x80"
108
                  : "=a" (res)
109
                  : "0"(SYS_futex), "b" (addr), "c"(op),
110
                    "d"(val), "S"(0)
111
                  : "memory");
112
  return res;
113
}
114
 
115
# endif /* __PIC__ */
116
 
117
static inline void
118
futex_wait (int *addr, int val)
119
{
120
  long res = sys_futex0 (addr, gomp_futex_wait, val);
121
  if (__builtin_expect (res == -ENOSYS, 0))
122
    {
123
      gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
124
      gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
125
      sys_futex0 (addr, gomp_futex_wait, val);
126
    }
127
}
128
 
129
static inline void
130
futex_wake (int *addr, int count)
131
{
132
  long res = sys_futex0 (addr, gomp_futex_wake, count);
133
  if (__builtin_expect (res == -ENOSYS, 0))
134
    {
135
      gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
136
      gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
137
      sys_futex0 (addr, gomp_futex_wake, count);
138
    }
139
}
140
 
141
#endif /* __LP64__ */
142
 
143
static inline void
144
cpu_relax (void)
145
{
146
  __asm volatile ("rep; nop" : : : "memory");
147
}
148
 
149
static inline void
150
atomic_write_barrier (void)
151
{
152
  __sync_synchronize ();
153
}

powered by: WebSVN 2.1.0

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