_fallocking.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  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 $ */
  25. /*
  26. Copyright (c) 1992 X Consortium
  27. Permission is hereby granted, free of charge, to any person obtaining a copy
  28. of this software and associated documentation files (the "Software"), to deal
  29. in the Software without restriction, including without limitation the rights
  30. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  31. copies of the Software, and to permit persons to whom the Software is
  32. furnished to do so, subject to the following conditions:
  33. The above copyright notice and this permission notice shall be included in
  34. all copies or substantial portions of the Software.
  35. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  37. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  39. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  40. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  41. Except as contained in this notice, the name of the X Consortium shall not be
  42. used in advertising or otherwise to promote the sale, use or other dealings
  43. in this Software without prior written authorization from the X Consortium.
  44. */
  45. /*
  46. * Author: Stephen Gildea, MIT X Consortium
  47. *
  48. * locking.h - data types for C Threads locking.
  49. * Used by XlibInt.c, locking.c, LockDis.c
  50. */
  51. #ifndef _X_locking_H_
  52. #define _X_locking_H_
  53. #define xmalloc(s) Xmalloc(s)
  54. #define xfree(s) Xfree(s)
  55. #include <X11/Xthreads.h>
  56. struct _XCVList {
  57. xcondition_t cv;
  58. xReply *buf;
  59. struct _XCVList *next;
  60. };
  61. extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */
  62. void
  63. );
  64. /* Display->lock is a pointer to one of these */
  65. struct _XLockInfo {
  66. xmutex_t mutex; /* mutex for critical sections */
  67. int reply_bytes_left; /* nbytes of the reply still to read */
  68. Bool reply_was_read; /* _XReadEvents read a reply for _XReply */
  69. struct _XCVList *reply_awaiters; /* list of CVs for _XReply */
  70. struct _XCVList **reply_awaiters_tail;
  71. struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */
  72. struct _XCVList **event_awaiters_tail;
  73. Bool reply_first; /* who may read, reply queue or event queue */
  74. /* for XLockDisplay */
  75. int locking_level; /* how many times into XLockDisplay we are */
  76. xthread_t locking_thread; /* thread that did XLockDisplay */
  77. xcondition_t cv; /* wait if another thread has XLockDisplay */
  78. xthread_t reading_thread; /* cache */
  79. xthread_t conni_thread; /* thread in XProcessInternalConnection */
  80. xcondition_t writers; /* wait for writable */
  81. int num_free_cvls;
  82. struct _XCVList *free_cvls;
  83. /* used only in XlibInt.c */
  84. void (*pop_reader)(
  85. Display* /* dpy */,
  86. struct _XCVList** /* list */,
  87. struct _XCVList*** /* tail */
  88. );
  89. struct _XCVList *(*push_reader)(
  90. Display * /* dpy */,
  91. struct _XCVList*** /* tail */
  92. );
  93. void (*condition_wait)(
  94. xcondition_t /* cv */,
  95. xmutex_t /* mutex */
  96. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  97. , char* /* file */,
  98. int /* line */
  99. #endif
  100. );
  101. void (*internal_lock_display)(
  102. Display* /* dpy */,
  103. Bool /* wskip */
  104. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  105. , char* /* file */,
  106. int /* line */
  107. #endif
  108. );
  109. /* used in XlibInt.c and locking.c */
  110. void (*condition_signal)(
  111. xcondition_t /* cv */
  112. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  113. , char* /* file */,
  114. int /* line */
  115. #endif
  116. );
  117. void (*condition_broadcast)(
  118. xcondition_t /* cv */
  119. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  120. , char* /* file */,
  121. int /* line */
  122. #endif
  123. );
  124. /* used in XlibInt.c and XLockDis.c */
  125. void (*lock_wait)(
  126. Display* /* dpy */
  127. );
  128. void (*user_lock_display)(
  129. Display* /* dpy */
  130. );
  131. void (*user_unlock_display)(
  132. Display* /* dpy */
  133. );
  134. struct _XCVList *(*create_cvl)(
  135. Display * /* dpy */
  136. );
  137. };
  138. #define UnlockNextEventReader(d) if ((d)->lock) \
  139. (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail)
  140. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  141. #define ConditionWait(d,c) if ((d)->lock) \
  142. (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__)
  143. #define ConditionSignal(d,c) if ((d)->lock) \
  144. (*(d)->lock->condition_signal)(c,__FILE__,__LINE__)
  145. #define ConditionBroadcast(d,c) if ((d)->lock) \
  146. (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__)
  147. #else
  148. #define ConditionWait(d,c) if ((d)->lock) \
  149. (*(d)->lock->condition_wait)(c, (d)->lock->mutex)
  150. #define ConditionSignal(d,c) if ((d)->lock) \
  151. (*(d)->lock->condition_signal)(c)
  152. #define ConditionBroadcast(d,c) if ((d)->lock) \
  153. (*(d)->lock->condition_broadcast)(c)
  154. #endif
  155. typedef struct _LockInfoRec {
  156. xmutex_t lock;
  157. } LockInfoRec;
  158. #endif /* _X_locking_H_ */