home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / locking.h < prev    next >
C/C++ Source or Header  |  2000-06-08  |  5KB  |  170 lines

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