locking.h revision 1ab64890
11ab64890Smrg/* $Xorg: locking.h,v 1.4 2001/02/09 02:03:40 xorgcvs Exp $ */ 21ab64890Smrg/* 31ab64890Smrg 41ab64890SmrgCopyright 1992, 1998 The Open Group 51ab64890Smrg 61ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 71ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 81ab64890Smrgthe above copyright notice appear in all copies and that both that 91ab64890Smrgcopyright notice and this permission notice appear in supporting 101ab64890Smrgdocumentation. 111ab64890Smrg 121ab64890SmrgThe above copyright notice and this permission notice shall be included in 131ab64890Smrgall copies or substantial portions of the Software. 141ab64890Smrg 151ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161ab64890SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171ab64890SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 181ab64890SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 191ab64890SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 201ab64890SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 211ab64890Smrg 221ab64890SmrgExcept as contained in this notice, the name of The Open Group shall not be 231ab64890Smrgused in advertising or otherwise to promote the sale, use or other dealings 241ab64890Smrgin this Software without prior written authorization from The Open Group. 251ab64890Smrg 261ab64890Smrg*/ 271ab64890Smrg/* $XFree86: xc/lib/X11/locking.h,v 1.4 2001/12/14 19:54:10 dawes Exp $ */ 281ab64890Smrg 291ab64890Smrg/* 301ab64890Smrg * Author: Stephen Gildea, MIT X Consortium 311ab64890Smrg * 321ab64890Smrg * locking.h - data types for C Threads locking. 331ab64890Smrg * Used by XlibInt.c, locking.c, LockDis.c 341ab64890Smrg */ 351ab64890Smrg 361ab64890Smrg#ifndef _X_locking_H_ 371ab64890Smrg#define _X_locking_H_ 381ab64890Smrg 391ab64890Smrg#define xmalloc(s) Xmalloc(s) 401ab64890Smrg#define xfree(s) Xfree(s) 411ab64890Smrg#include <X11/Xthreads.h> 421ab64890Smrg 431ab64890Smrgstruct _XCVList { 441ab64890Smrg xcondition_t cv; 451ab64890Smrg xReply *buf; 461ab64890Smrg struct _XCVList *next; 471ab64890Smrg}; 481ab64890Smrg 491ab64890Smrgextern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */ 501ab64890Smrg void 511ab64890Smrg); 521ab64890Smrg 531ab64890Smrg/* Display->lock is a pointer to one of these */ 541ab64890Smrg 551ab64890Smrgstruct _XLockInfo { 561ab64890Smrg xmutex_t mutex; /* mutex for critical sections */ 571ab64890Smrg int reply_bytes_left; /* nbytes of the reply still to read */ 581ab64890Smrg Bool reply_was_read; /* _XReadEvents read a reply for _XReply */ 591ab64890Smrg struct _XCVList *reply_awaiters; /* list of CVs for _XReply */ 601ab64890Smrg struct _XCVList **reply_awaiters_tail; 611ab64890Smrg struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */ 621ab64890Smrg struct _XCVList **event_awaiters_tail; 631ab64890Smrg Bool reply_first; /* who may read, reply queue or event queue */ 641ab64890Smrg /* for XLockDisplay */ 651ab64890Smrg int locking_level; /* how many times into XLockDisplay we are */ 661ab64890Smrg xthread_t locking_thread; /* thread that did XLockDisplay */ 671ab64890Smrg xcondition_t cv; /* wait if another thread has XLockDisplay */ 681ab64890Smrg xthread_t reading_thread; /* cache */ 691ab64890Smrg xthread_t conni_thread; /* thread in XProcessInternalConnection */ 701ab64890Smrg xcondition_t writers; /* wait for writable */ 711ab64890Smrg int num_free_cvls; 721ab64890Smrg struct _XCVList *free_cvls; 731ab64890Smrg /* used only in XlibInt.c */ 741ab64890Smrg void (*pop_reader)( 751ab64890Smrg Display* /* dpy */, 761ab64890Smrg struct _XCVList** /* list */, 771ab64890Smrg struct _XCVList*** /* tail */ 781ab64890Smrg ); 791ab64890Smrg struct _XCVList *(*push_reader)( 801ab64890Smrg Display * /* dpy */, 811ab64890Smrg struct _XCVList*** /* tail */ 821ab64890Smrg ); 831ab64890Smrg void (*condition_wait)( 841ab64890Smrg xcondition_t /* cv */, 851ab64890Smrg xmutex_t /* mutex */ 861ab64890Smrg#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 871ab64890Smrg , char* /* file */, 881ab64890Smrg int /* line */ 891ab64890Smrg#endif 901ab64890Smrg ); 911ab64890Smrg void (*internal_lock_display)( 921ab64890Smrg Display* /* dpy */, 931ab64890Smrg Bool /* wskip */ 941ab64890Smrg#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 951ab64890Smrg , char* /* file */, 961ab64890Smrg int /* line */ 971ab64890Smrg#endif 981ab64890Smrg ); 991ab64890Smrg /* used in XlibInt.c and locking.c */ 1001ab64890Smrg void (*condition_signal)( 1011ab64890Smrg xcondition_t /* cv */ 1021ab64890Smrg#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 1031ab64890Smrg , char* /* file */, 1041ab64890Smrg int /* line */ 1051ab64890Smrg#endif 1061ab64890Smrg ); 1071ab64890Smrg void (*condition_broadcast)( 1081ab64890Smrg xcondition_t /* cv */ 1091ab64890Smrg#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 1101ab64890Smrg , char* /* file */, 1111ab64890Smrg int /* line */ 1121ab64890Smrg#endif 1131ab64890Smrg ); 1141ab64890Smrg /* used in XlibInt.c and XLockDis.c */ 1151ab64890Smrg void (*lock_wait)( 1161ab64890Smrg Display* /* dpy */ 1171ab64890Smrg ); 1181ab64890Smrg void (*user_lock_display)( 1191ab64890Smrg Display* /* dpy */ 1201ab64890Smrg ); 1211ab64890Smrg void (*user_unlock_display)( 1221ab64890Smrg Display* /* dpy */ 1231ab64890Smrg ); 1241ab64890Smrg struct _XCVList *(*create_cvl)( 1251ab64890Smrg Display * /* dpy */ 1261ab64890Smrg ); 1271ab64890Smrg}; 1281ab64890Smrg 1291ab64890Smrg#define UnlockNextEventReader(d) if ((d)->lock) \ 1301ab64890Smrg (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail) 1311ab64890Smrg 1321ab64890Smrg#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) 1331ab64890Smrg#define ConditionWait(d,c) if ((d)->lock) \ 1341ab64890Smrg (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__) 1351ab64890Smrg#define ConditionSignal(d,c) if ((d)->lock) \ 1361ab64890Smrg (*(d)->lock->condition_signal)(c,__FILE__,__LINE__) 1371ab64890Smrg#define ConditionBroadcast(d,c) if ((d)->lock) \ 1381ab64890Smrg (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__) 1391ab64890Smrg#else 1401ab64890Smrg#define ConditionWait(d,c) if ((d)->lock) \ 1411ab64890Smrg (*(d)->lock->condition_wait)(c, (d)->lock->mutex) 1421ab64890Smrg#define ConditionSignal(d,c) if ((d)->lock) \ 1431ab64890Smrg (*(d)->lock->condition_signal)(c) 1441ab64890Smrg#define ConditionBroadcast(d,c) if ((d)->lock) \ 1451ab64890Smrg (*(d)->lock->condition_broadcast)(c) 1461ab64890Smrg#endif 1471ab64890Smrg 1481ab64890Smrgtypedef struct _LockInfoRec { 1491ab64890Smrg xmutex_t lock; 1501ab64890Smrg} LockInfoRec; 1511ab64890Smrg 1521ab64890Smrg/* XOpenDis.c */ 1531ab64890Smrgextern int (*_XInitDisplayLock_fn)(Display *dpy); 1541ab64890Smrgextern void (*_XFreeDisplayLock_fn)(Display *dpy); 1551ab64890Smrg 1561ab64890Smrg#endif /* _X_locking_H_ */ 157