Tue Jul 9 09:37:55 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / mach / libc-lock.h
blob0639fc6b22ba7ae740d04869585348cba58161e5
1 /* libc-internal interface for mutex locks. Mach cthreads version.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #ifndef _LIBC_LOCK_H
21 #define _LIBC_LOCK_H 1
23 #ifdef _LIBC
24 #include <cthreads.h>
25 #define __libc_lock_t struct mutex
26 #else
27 typedef struct __libc_lock_opaque__ __libc_lock_t;
28 #endif
30 /* Define a lock variable NAME with storage class CLASS. The lock must be
31 initialized with __libc_lock_init before it can be used (or define it
32 with __libc_lock_define_initialized, below). Use `extern' for CLASS to
33 declare a lock defined in another module. In public structure
34 definitions, the lock element must come last, because its storage size
35 will not be known outside of libc. (Or you can use a pointer to the
36 lock structure; i.e. NAME begins with a `*'.) */
37 #define __libc_lock_define(CLASS,NAME)
38 CLASS __libc_lock_t NAME;
40 /* Define an initialized lock variable NAME with storage class CLASS. */
41 #define __libc_lock_define_initialized(CLASS,NAME) \
42 CLASS __libc_lock_t NAME = MUTEX_INITIALIZER;
44 /* Initialize the named lock variable, leaving it in a consistent, unlocked
45 state. */
46 #define __libc_lock_init(NAME) __mutex_init (&(NAME))
48 /* Finalize the named lock variable, which must be locked. It cannot be
49 used again until __libc_lock_init is called again on it. This must be
50 called on a lock variable before the containing storage is reused. */
51 #define __libc_lock_fini(NAME) __mutex_unlock (&(NAME))
53 /* Lock the named lock variable. */
54 #define __libc_lock_lock(NAME) __mutex_lock (&(NAME))
56 /* Unlock the named lock variable. */
57 #define __libc_lock_unlock(NAME) __mutex_unlock (&(NAME))
60 #endif /* libc-lock.h */