1 /* libc-internal interface for mutex locks. Mach cthreads version.
2 Copyright (C) 1996, 1997 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 not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
21 #define _LIBC_LOCK_H 1
25 #define __libc_lock_t struct mutex
27 typedef struct __libc_lock_opaque__ __libc_lock_t;
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 you must use a pointer to the lock structure (i.e., NAME
35 begins with a `*'), because its storage size will not be known outside
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
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 /* Lock the named lock variable. */
57 #define __libc_lock_trylock(NAME) (!__mutex_trylock (&(NAME)))
59 /* Unlock the named lock variable. */
60 #define __libc_lock_unlock(NAME) __mutex_unlock (&(NAME))
62 /* Start a critical region with a cleanup function */
63 #define __libc_cleanup_region_start(FCT, ARG) \
65 typeof (FCT) __save_FCT = FCT; \
66 typeof (ARG) __save_ARG = ARG; \
67 /* close brace is in __libc_cleanup_region_end below. */
69 /* End a critical region started with __libc_cleanup_region_start. */
70 #define __libc_cleanup_region_end(DOIT) \
72 (*__save_FCT)(__save_ARG); \
77 /* We need portable names for some functions. E.g., when they are
78 used as argument to __libc_cleanup_region_start. */
79 #define __libc_mutex_unlock __mutex_unlock
82 /* XXX until cthreads supports recursive locks */
83 #define __libc_lock_define_initialized_recursive __libc_lock_define_initialized
84 #define __libc_lock_init_recursive __libc_lock_init
85 #define __libc_lock_fini_recursive __libc_lock_fini
86 #define __libc_lock_trylock_recursive __libc_lock_trylock
87 #define __libc_lock_unlock_recursive __libc_lock_unlock
88 #define __libc_lock_lock_recursive __libc_lock_lock
90 /* XXX until cthreads supports recursive locks */
91 #define __libc_lock_define_initialized_recursive __libc_lock_define_initialized
92 #define __libc_lock_init_recursive __libc_lock_init
93 #define __libc_lock_fini_recursive __libc_lock_fini
94 #define __libc_lock_trylock_recursive __libc_lock_trylock
95 #define __libc_lock_unlock_recursive __libc_lock_unlock
96 #define __libc_lock_lock_recursive __libc_lock_lock
98 #endif /* libc-lock.h */