2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* locking.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:43 */
24 /* $XConsortium: _fallocking.h /main/1 1996/04/08 15:21:32 cde-fuj $ */
27 Copyright (c) 1992 X Consortium
29 Permission is hereby granted, free of charge, to any person obtaining a copy
30 of this software and associated documentation files (the "Software"), to deal
31 in the Software without restriction, including without limitation the rights
32 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33 copies of the Software, and to permit persons to whom the Software is
34 furnished to do so, subject to the following conditions:
36 The above copyright notice and this permission notice shall be included in
37 all copies or substantial portions of the Software.
39 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
43 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 Except as contained in this notice, the name of the X Consortium shall not be
47 used in advertising or otherwise to promote the sale, use or other dealings
48 in this Software without prior written authorization from the X Consortium.
53 * Author: Stephen Gildea, MIT X Consortium
55 * locking.h - data types for C Threads locking.
56 * Used by XlibInt.c, locking.c, LockDis.c
62 #define xmalloc(s) Xmalloc(s)
63 #define xfree(s) Xfree(s)
64 #include <X11/Xthreads.h>
69 struct _XCVList *next;
72 extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */
73 #if NeedFunctionPrototypes
78 /* Display->lock is a pointer to one of these */
81 xmutex_t mutex; /* mutex for critical sections */
82 int reply_bytes_left; /* nbytes of the reply still to read */
83 Bool reply_was_read; /* _XReadEvents read a reply for _XReply */
84 struct _XCVList *reply_awaiters; /* list of CVs for _XReply */
85 struct _XCVList **reply_awaiters_tail;
86 struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */
87 struct _XCVList **event_awaiters_tail;
88 Bool reply_first; /* who may read, reply queue or event queue */
89 /* for XLockDisplay */
90 int locking_level; /* how many times into XLockDisplay we are */
91 xthread_t locking_thread; /* thread that did XLockDisplay */
92 xcondition_t cv; /* wait if another thread has XLockDisplay */
93 xthread_t reading_thread; /* cache */
94 xthread_t conni_thread; /* thread in XProcessInternalConnection */
95 xcondition_t writers; /* wait for writable */
97 struct _XCVList *free_cvls;
98 /* used only in XlibInt.c */
100 #if NeedNestedPrototypes
102 struct _XCVList** /* list */,
103 struct _XCVList*** /* tail */
106 struct _XCVList *(*push_reader)(
107 #if NeedNestedPrototypes
109 struct _XCVList*** /* tail */
112 void (*condition_wait)(
113 #if NeedNestedPrototypes
114 xcondition_t /* cv */,
116 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
122 void (*internal_lock_display)(
123 #if NeedNestedPrototypes
126 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
132 /* used in XlibInt.c and locking.c */
133 void (*condition_signal)(
134 #if NeedNestedPrototypes
135 xcondition_t /* cv */
136 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
142 void (*condition_broadcast)(
143 #if NeedNestedPrototypes
144 xcondition_t /* cv */
145 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
151 /* used in XlibInt.c and XLockDis.c */
153 #if NeedNestedPrototypes
157 void (*user_lock_display)(
158 #if NeedNestedPrototypes
162 void (*user_unlock_display)(
163 #if NeedNestedPrototypes
167 struct _XCVList *(*create_cvl)(
168 #if NeedNestedPrototypes
174 #define UnlockNextEventReader(d) if ((d)->lock) \
175 (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail)
177 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
178 #define ConditionWait(d,c) if ((d)->lock) \
179 (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__)
180 #define ConditionSignal(d,c) if ((d)->lock) \
181 (*(d)->lock->condition_signal)(c,__FILE__,__LINE__)
182 #define ConditionBroadcast(d,c) if ((d)->lock) \
183 (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__)
185 #define ConditionWait(d,c) if ((d)->lock) \
186 (*(d)->lock->condition_wait)(c, (d)->lock->mutex)
187 #define ConditionSignal(d,c) if ((d)->lock) \
188 (*(d)->lock->condition_signal)(c)
189 #define ConditionBroadcast(d,c) if ((d)->lock) \
190 (*(d)->lock->condition_broadcast)(c)
193 typedef struct _LockInfoRec {
197 #endif /* _X_locking_H_ */