locking.h revision 1ab64890
1/* $Xorg: locking.h,v 1.4 2001/02/09 02:03:40 xorgcvs Exp $ */ 2/* 3 4Copyright 1992, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included in 13all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall not be 23used in advertising or otherwise to promote the sale, use or other dealings 24in this Software without prior written authorization from The Open Group. 25 26*/ 27/* $XFree86: xc/lib/X11/locking.h,v 1.4 2001/12/14 19:54:10 dawes Exp $ */ 28 29/* 30 * Author: Stephen Gildea, MIT X Consortium 31 * 32 * locking.h - data types for C Threads locking. 33 * Used by XlibInt.c, locking.c, LockDis.c 34 */ 35 36#ifndef _X_locking_H_ 37#define _X_locking_H_ 38 39#define xmalloc(s) Xmalloc(s) 40#define xfree(s) Xfree(s) 41#include <X11/Xthreads.h> 42 43struct _XCVList { 44 xcondition_t cv; 45 xReply *buf; 46 struct _XCVList *next; 47}; 48 49extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */ 50 void 51); 52 53/* Display->lock is a pointer to one of these */ 54 55struct _XLockInfo { 56 xmutex_t mutex; /* mutex for critical sections */ 57 int reply_bytes_left; /* nbytes of the reply still to read */ 58 Bool reply_was_read; /* _XReadEvents read a reply for _XReply */ 59 struct _XCVList *reply_awaiters; /* list of CVs for _XReply */ 60 struct _XCVList **reply_awaiters_tail; 61 struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */ 62 struct _XCVList **event_awaiters_tail; 63 Bool reply_first; /* who may read, reply queue or event queue */ 64 /* for XLockDisplay */ 65 int locking_level; /* how many times into XLockDisplay we are */ 66 xthread_t locking_thread; /* thread that did XLockDisplay */ 67 xcondition_t cv; /* wait if another thread has XLockDisplay */ 68 xthread_t reading_thread; /* cache */ 69 xthread_t conni_thread; /* thread in XProcessInternalConnection */ 70 xcondition_t writers; /* wait for writable */ 71 int num_free_cvls; 72 struct _XCVList *free_cvls; 73 /* used only in XlibInt.c */ 74 void (*pop_reader)( 75 Display* /* dpy */, 76 struct _XCVList** /* list */, 77 struct _XCVList*** /* tail */ 78 ); 79 struct _XCVList *(*push_reader)( 80 Display * /* dpy */, 81 struct _XCVList*** /* tail */ 82 ); 83 void (*condition_wait)( 84 xcondition_t /* cv */, 85 xmutex_t /* mutex */ 86#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 87 , char* /* file */, 88 int /* line */ 89#endif 90 ); 91 void (*internal_lock_display)( 92 Display* /* dpy */, 93 Bool /* wskip */ 94#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 95 , char* /* file */, 96 int /* line */ 97#endif 98 ); 99 /* used in XlibInt.c and locking.c */ 100 void (*condition_signal)( 101 xcondition_t /* cv */ 102#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 103 , char* /* file */, 104 int /* line */ 105#endif 106 ); 107 void (*condition_broadcast)( 108 xcondition_t /* cv */ 109#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 110 , char* /* file */, 111 int /* line */ 112#endif 113 ); 114 /* used in XlibInt.c and XLockDis.c */ 115 void (*lock_wait)( 116 Display* /* dpy */ 117 ); 118 void (*user_lock_display)( 119 Display* /* dpy */ 120 ); 121 void (*user_unlock_display)( 122 Display* /* dpy */ 123 ); 124 struct _XCVList *(*create_cvl)( 125 Display * /* dpy */ 126 ); 127}; 128 129#define UnlockNextEventReader(d) if ((d)->lock) \ 130 (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail) 131 132#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 133#define ConditionWait(d,c) if ((d)->lock) \ 134 (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__) 135#define ConditionSignal(d,c) if ((d)->lock) \ 136 (*(d)->lock->condition_signal)(c,__FILE__,__LINE__) 137#define ConditionBroadcast(d,c) if ((d)->lock) \ 138 (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__) 139#else 140#define ConditionWait(d,c) if ((d)->lock) \ 141 (*(d)->lock->condition_wait)(c, (d)->lock->mutex) 142#define ConditionSignal(d,c) if ((d)->lock) \ 143 (*(d)->lock->condition_signal)(c) 144#define ConditionBroadcast(d,c) if ((d)->lock) \ 145 (*(d)->lock->condition_broadcast)(c) 146#endif 147 148typedef struct _LockInfoRec { 149 xmutex_t lock; 150} LockInfoRec; 151 152/* XOpenDis.c */ 153extern int (*_XInitDisplayLock_fn)(Display *dpy); 154extern void (*_XFreeDisplayLock_fn)(Display *dpy); 155 156#endif /* _X_locking_H_ */ 157