3 Copyright 1992, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * Author: Stephen Gildea, MIT X Consortium
30 * locking.h - data types for C Threads locking.
31 * Used by XlibInt.c, locking.c, LockDis.c
37 #define xmalloc(s) Xmalloc(s)
38 #define xfree(s) Xfree(s)
39 #include <X11/Xthreads.h>
44 struct _XCVList *next;
47 extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */
51 /* Display->lock is a pointer to one of these */
54 xmutex_t mutex; /* mutex for critical sections */
55 int reply_bytes_left; /* nbytes of the reply still to read */
56 Bool reply_was_read; /* _XReadEvents read a reply for _XReply */
57 struct _XCVList *reply_awaiters; /* list of CVs for _XReply */
58 struct _XCVList **reply_awaiters_tail;
59 struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */
60 struct _XCVList **event_awaiters_tail;
61 Bool reply_first; /* who may read, reply queue or event queue */
62 /* for XLockDisplay */
63 int locking_level; /* how many times into XLockDisplay we are */
64 xthread_t locking_thread; /* thread that did XLockDisplay */
65 xcondition_t cv; /* wait if another thread has XLockDisplay */
66 xthread_t reading_thread; /* cache */
67 xthread_t conni_thread; /* thread in XProcessInternalConnection */
68 xcondition_t writers; /* wait for writable */
70 struct _XCVList *free_cvls;
71 /* used only in XlibInt.c */
74 struct _XCVList** /* list */,
75 struct _XCVList*** /* tail */
77 struct _XCVList *(*push_reader)(
79 struct _XCVList*** /* tail */
81 void (*condition_wait)(
82 xcondition_t /* cv */,
84 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
89 void (*internal_lock_display)(
92 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
97 /* used in XlibInt.c and locking.c */
98 void (*condition_signal)(
100 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
105 void (*condition_broadcast)(
106 xcondition_t /* cv */
107 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
112 /* used in XlibInt.c and XLockDis.c */
116 void (*user_lock_display)(
119 void (*user_unlock_display)(
122 struct _XCVList *(*create_cvl)(
127 #define UnlockNextEventReader(d) if ((d)->lock) \
128 (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail)
130 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
131 #define ConditionWait(d,c) if ((d)->lock) \
132 (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__)
133 #define ConditionSignal(d,c) if ((d)->lock) \
134 (*(d)->lock->condition_signal)(c,__FILE__,__LINE__)
135 #define ConditionBroadcast(d,c) if ((d)->lock) \
136 (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__)
138 #define ConditionWait(d,c) if ((d)->lock) \
139 (*(d)->lock->condition_wait)(c, (d)->lock->mutex)
140 #define ConditionSignal(d,c) if ((d)->lock) \
141 (*(d)->lock->condition_signal)(c)
142 #define ConditionBroadcast(d,c) if ((d)->lock) \
143 (*(d)->lock->condition_broadcast)(c)
146 typedef struct _LockInfoRec {
151 extern int (*_XInitDisplayLock_fn)(Display *dpy);
152 extern void (*_XFreeDisplayLock_fn)(Display *dpy);
154 #endif /* _X_locking_H_ */