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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libgomp/] [config/] [posix95/] [lock.c] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 273 jeremybenn
/* Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc.
2
 
3
   This file is part of the GNU OpenMP Library (libgomp).
4
 
5
   Libgomp is free software; you can redistribute it and/or modify it
6
   under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3, or (at your option)
8
   any later version.
9
 
10
   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
11
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
   more details.
14
 
15
   Under Section 7 of GPL version 3, you are granted additional
16
   permissions described in the GCC Runtime Library Exception, version
17
   3.1, as published by the Free Software Foundation.
18
 
19
   You should have received a copy of the GNU General Public License and
20
   a copy of the GCC Runtime Library Exception along with this program;
21
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22
   <http://www.gnu.org/licenses/>.  */
23
 
24
/* This is the POSIX95 implementation of the public OpenMP locking primitives.
25
 
26
   Because OpenMP uses different entry points for normal and recursive
27
   locks, and pthreads uses only one entry point, a system may be able
28
   to do better and streamline the locking as well as reduce the size
29
   of the types exported.  */
30
 
31
#include "libgomp.h"
32
 
33
#ifdef HAVE_BROKEN_POSIX_SEMAPHORES
34
void
35
gomp_init_lock_30 (omp_lock_t *lock)
36
{
37
  pthread_mutex_init (lock, NULL);
38
}
39
 
40
void
41
gomp_destroy_lock_30 (omp_lock_t *lock)
42
{
43
  pthread_mutex_destroy (lock);
44
}
45
 
46
void
47
gomp_set_lock_30 (omp_lock_t *lock)
48
{
49
  pthread_mutex_lock (lock);
50
}
51
 
52
void
53
gomp_unset_lock_30 (omp_lock_t *lock)
54
{
55
  pthread_mutex_unlock (lock);
56
}
57
 
58
int
59
gomp_test_lock_30 (omp_lock_t *lock)
60
{
61
  return pthread_mutex_trylock (lock) == 0;
62
}
63
 
64
void
65
gomp_init_nest_lock_30 (omp_nest_lock_t *lock)
66
{
67
  pthread_mutex_init (&lock->lock, NULL);
68
  lock->owner = NULL;
69
  lock->count = 0;
70
}
71
 
72
void
73
gomp_destroy_nest_lock_30 (omp_nest_lock_t *lock)
74
{
75
  pthread_mutex_destroy (&lock->lock);
76
}
77
 
78
void
79
gomp_set_nest_lock_30 (omp_nest_lock_t *lock)
80
{
81
  void *me = gomp_icv (true);
82
 
83
  if (lock->owner != me)
84
    {
85
      pthread_mutex_lock (&lock->lock);
86
      lock->owner = me;
87
    }
88
 
89
  lock->count++;
90
}
91
 
92
void
93
gomp_unset_nest_lock_30 (omp_nest_lock_t *lock)
94
{
95
  lock->count--;
96
 
97
  if (lock->count == 0)
98
    {
99
      lock->owner = NULL;
100
      pthread_mutex_unlock (&lock->lock);
101
    }
102
}
103
 
104
int
105
gomp_test_nest_lock_30 (omp_nest_lock_t *lock)
106
{
107
  void *me = gomp_icv (true);
108
 
109
  if (lock->owner != me)
110
    {
111
      if (pthread_mutex_trylock (&lock->lock) != 0)
112
        return 0;
113
      lock->owner = me;
114
    }
115
 
116
  return ++lock->count;
117
}
118
 
119
#else
120
 
121
void
122
gomp_init_lock_30 (omp_lock_t *lock)
123
{
124
  sem_init (lock, 0, 1);
125
}
126
 
127
void
128
gomp_destroy_lock_30 (omp_lock_t *lock)
129
{
130
  sem_destroy (lock);
131
}
132
 
133
void
134
gomp_set_lock_30 (omp_lock_t *lock)
135
{
136
  while (sem_wait (lock) != 0)
137
    ;
138
}
139
 
140
void
141
gomp_unset_lock_30 (omp_lock_t *lock)
142
{
143
  sem_post (lock);
144
}
145
 
146
int
147
gomp_test_lock_30 (omp_lock_t *lock)
148
{
149
  return sem_trywait (lock) == 0;
150
}
151
 
152
void
153
gomp_init_nest_lock_30 (omp_nest_lock_t *lock)
154
{
155
  sem_init (&lock->lock, 0, 1);
156
  lock->count = 0;
157
  lock->owner = NULL;
158
}
159
 
160
void
161
gomp_destroy_nest_lock_30 (omp_nest_lock_t *lock)
162
{
163
  sem_destroy (&lock->lock);
164
}
165
 
166
void
167
gomp_set_nest_lock_30 (omp_nest_lock_t *lock)
168
{
169
  void *me = gomp_icv (true);
170
 
171
  if (lock->owner != me)
172
    {
173
      while (sem_wait (&lock->lock) != 0)
174
        ;
175
      lock->owner = me;
176
    }
177
  lock->count++;
178
}
179
 
180
void
181
gomp_unset_nest_lock_30 (omp_nest_lock_t *lock)
182
{
183
  if (--lock->count == 0)
184
    {
185
      lock->owner = NULL;
186
      sem_post (&lock->lock);
187
    }
188
}
189
 
190
int
191
gomp_test_nest_lock_30 (omp_nest_lock_t *lock)
192
{
193
  void *me = gomp_icv (true);
194
 
195
  if (lock->owner != me)
196
    {
197
      if (sem_trywait (&lock->lock) != 0)
198
        return 0;
199
      lock->owner = me;
200
    }
201
 
202
  return ++lock->count;
203
}
204
#endif
205
 
206
#ifdef LIBGOMP_GNU_SYMBOL_VERSIONING
207
void
208
gomp_init_lock_25 (omp_lock_25_t *lock)
209
{
210
  pthread_mutex_init (lock, NULL);
211
}
212
 
213
void
214
gomp_destroy_lock_25 (omp_lock_25_t *lock)
215
{
216
  pthread_mutex_destroy (lock);
217
}
218
 
219
void
220
gomp_set_lock_25 (omp_lock_25_t *lock)
221
{
222
  pthread_mutex_lock (lock);
223
}
224
 
225
void
226
gomp_unset_lock_25 (omp_lock_25_t *lock)
227
{
228
  pthread_mutex_unlock (lock);
229
}
230
 
231
int
232
gomp_test_lock_25 (omp_lock_25_t *lock)
233
{
234
  return pthread_mutex_trylock (lock) == 0;
235
}
236
 
237
void
238
gomp_init_nest_lock_25 (omp_nest_lock_25_t *lock)
239
{
240
  pthread_mutex_init (&lock->lock, NULL);
241
  lock->owner = (pthread_t) 0;
242
  lock->count = 0;
243
}
244
 
245
void
246
gomp_destroy_nest_lock_25 (omp_nest_lock_25_t *lock)
247
{
248
  pthread_mutex_destroy (&lock->lock);
249
}
250
 
251
void
252
gomp_set_nest_lock_25 (omp_nest_lock_25_t *lock)
253
{
254
  pthread_t me = pthread_self ();
255
 
256
  if (lock->owner != me)
257
    {
258
      pthread_mutex_lock (&lock->lock);
259
      lock->owner = me;
260
    }
261
 
262
  lock->count++;
263
}
264
 
265
void
266
gomp_unset_nest_lock_25 (omp_nest_lock_25_t *lock)
267
{
268
  lock->count--;
269
 
270
  if (lock->count == 0)
271
    {
272
      lock->owner = (pthread_t) 0;
273
      pthread_mutex_unlock (&lock->lock);
274
    }
275
}
276
 
277
int
278
gomp_test_nest_lock_25 (omp_nest_lock_25_t *lock)
279
{
280
  pthread_t me = pthread_self ();
281
 
282
  if (lock->owner != me)
283
    {
284
      if (pthread_mutex_trylock (&lock->lock) != 0)
285
        return 0;
286
      lock->owner = me;
287
    }
288
 
289
  return ++lock->count;
290
}
291
 
292
omp_lock_symver (omp_init_lock)
293
omp_lock_symver (omp_destroy_lock)
294
omp_lock_symver (omp_set_lock)
295
omp_lock_symver (omp_unset_lock)
296
omp_lock_symver (omp_test_lock)
297
omp_lock_symver (omp_init_nest_lock)
298
omp_lock_symver (omp_destroy_nest_lock)
299
omp_lock_symver (omp_set_nest_lock)
300
omp_lock_symver (omp_unset_nest_lock)
301
omp_lock_symver (omp_test_nest_lock)
302
 
303
#else
304
 
305
ialias (omp_init_lock)
306
ialias (omp_init_nest_lock)
307
ialias (omp_destroy_lock)
308
ialias (omp_destroy_nest_lock)
309
ialias (omp_set_lock)
310
ialias (omp_set_nest_lock)
311
ialias (omp_unset_lock)
312
ialias (omp_unset_nest_lock)
313
ialias (omp_test_lock)
314
ialias (omp_test_nest_lock)
315
 
316
#endif

powered by: WebSVN 2.1.0

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