UUID stuff from Ryan Raasch
[cegcc.git] / cegcc / src / gcc-4.3.2 / libgomp / config / posix95 / lock.c
blob2416f1131c781a10c846d01b7799b74582d9c975
1 /* Copyright (C) 2006 Free Software Foundation, Inc.
3 This file is part of the GNU OpenMP Library (libgomp).
5 Libgomp is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
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 Lesser General Public License for
13 more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with libgomp; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 MA 02110-1301, USA. */
20 /* As a special exception, if you link this library with other files, some
21 of which are compiled with GCC, to produce an executable, this library
22 does not by itself cause the resulting executable to be covered by the
23 GNU General Public License. This exception does not however invalidate
24 any other reasons why the executable file might be covered by the GNU
25 General Public License. */
27 /* This is the POSIX95 implementation of the public OpenMP locking primitives.
29 Because OpenMP uses different entry points for normal and recursive
30 locks, and pthreads uses only one entry point, a system may be able
31 to do better and streamline the locking as well as reduce the size
32 of the types exported. */
34 #include "libgomp.h"
37 void
38 omp_init_lock (omp_lock_t *lock)
40 pthread_mutex_init (lock, NULL);
43 void
44 omp_destroy_lock (omp_lock_t *lock)
46 pthread_mutex_destroy (lock);
49 void
50 omp_set_lock (omp_lock_t *lock)
52 pthread_mutex_lock (lock);
55 void
56 omp_unset_lock (omp_lock_t *lock)
58 pthread_mutex_unlock (lock);
61 int
62 omp_test_lock (omp_lock_t *lock)
64 return pthread_mutex_trylock (lock) == 0;
67 void
68 omp_init_nest_lock (omp_nest_lock_t *lock)
70 pthread_mutex_init (&lock->lock, NULL);
71 lock->owner = (pthread_t) 0;
72 lock->count = 0;
75 void
76 omp_destroy_nest_lock (omp_nest_lock_t *lock)
78 pthread_mutex_destroy (&lock->lock);
81 void
82 omp_set_nest_lock (omp_nest_lock_t *lock)
84 pthread_t me = pthread_self ();
86 if (lock->owner != me)
88 pthread_mutex_lock (&lock->lock);
89 lock->owner = me;
92 lock->count++;
95 void
96 omp_unset_nest_lock (omp_nest_lock_t *lock)
98 lock->count--;
100 if (lock->count == 0)
102 lock->owner = (pthread_t) 0;
103 pthread_mutex_unlock (&lock->lock);
108 omp_test_nest_lock (omp_nest_lock_t *lock)
110 pthread_t me = pthread_self ();
112 if (lock->owner != me)
114 if (pthread_mutex_trylock (&lock->lock) != 0)
115 return 0;
116 lock->owner = me;
119 return ++lock->count;
122 ialias (omp_init_lock)
123 ialias (omp_init_nest_lock)
124 ialias (omp_destroy_lock)
125 ialias (omp_destroy_nest_lock)
126 ialias (omp_set_lock)
127 ialias (omp_set_nest_lock)
128 ialias (omp_unset_lock)
129 ialias (omp_unset_nest_lock)
130 ialias (omp_test_lock)
131 ialias (omp_test_nest_lock)