Revert "dtudcfonted, dtudcexch: delete from repository"
[oweals/cde.git] / cde / programs / dtudcfonted / libfal / _fallocking.h
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
27 Copyright (c) 1992  X Consortium
28
29 Permission is hereby granted, free of charge, to any person obtaining a copy
30 of this software and associated documentation files (the "Software"), to deal
31 in the Software without restriction, including without limitation the rights
32 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33 copies of the Software, and to permit persons to whom the Software is
34 furnished to do so, subject to the following conditions:
35
36 The above copyright notice and this permission notice shall be included in
37 all copies or substantial portions of the Software.
38
39 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
42 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
43 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
46 Except as contained in this notice, the name of the X Consortium shall not be
47 used in advertising or otherwise to promote the sale, use or other dealings
48 in this Software without prior written authorization from the X Consortium.
49
50 */
51
52 /*
53  * Author: Stephen Gildea, MIT X Consortium
54  *
55  * locking.h - data types for C Threads locking.
56  * Used by XlibInt.c, locking.c, LockDis.c
57  */
58
59 #ifndef _X_locking_H_
60 #define _X_locking_H_
61
62 #define xmalloc(s) Xmalloc(s)
63 #define xfree(s) Xfree(s)
64 #include <X11/Xthreads.h>
65
66 struct _XCVList {
67     xcondition_t cv;
68     xReply *buf;
69     struct _XCVList *next;
70 };
71
72 extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */
73 #if NeedFunctionPrototypes
74     void
75 #endif
76 );
77
78 /* Display->lock is a pointer to one of these */
79
80 struct _XLockInfo {
81         xmutex_t mutex;         /* mutex for critical sections */
82         int reply_bytes_left;   /* nbytes of the reply still to read */
83         Bool reply_was_read;    /* _XReadEvents read a reply for _XReply */
84         struct _XCVList *reply_awaiters; /* list of CVs for _XReply */
85         struct _XCVList **reply_awaiters_tail;
86         struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */
87         struct _XCVList **event_awaiters_tail;
88         Bool reply_first;       /* who may read, reply queue or event queue */
89         /* for XLockDisplay */
90         int locking_level;      /* how many times into XLockDisplay we are */
91         xthread_t locking_thread; /* thread that did XLockDisplay */
92         xcondition_t cv;        /* wait if another thread has XLockDisplay */
93         xthread_t reading_thread; /* cache */
94         xthread_t conni_thread; /* thread in XProcessInternalConnection */
95         xcondition_t writers;   /* wait for writable */
96         int num_free_cvls;
97         struct _XCVList *free_cvls;
98         /* used only in XlibInt.c */
99         void (*pop_reader)(
100 #if NeedNestedPrototypes
101                            Display* /* dpy */,
102                            struct _XCVList** /* list */,
103                            struct _XCVList*** /* tail */
104 #endif
105                            );
106         struct _XCVList *(*push_reader)(
107 #if NeedNestedPrototypes
108                                         Display *          /* dpy */,
109                                         struct _XCVList*** /* tail */
110 #endif
111                                         );
112         void (*condition_wait)(
113 #if NeedNestedPrototypes
114                                xcondition_t /* cv */,
115                                xmutex_t /* mutex */
116 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
117                                , char* /* file */,
118                                int /* line */
119 #endif
120 #endif
121                                );
122         void (*internal_lock_display)(
123 #if NeedNestedPrototypes
124                                       Display* /* dpy */,
125                                       Bool /* wskip */
126 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
127                                       , char* /* file */,
128                                       int /* line */
129 #endif
130 #endif
131                                       );
132         /* used in XlibInt.c and locking.c */
133         void (*condition_signal)(
134 #if NeedNestedPrototypes
135                                  xcondition_t /* cv */
136 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
137                                  , char* /* file */,
138                                  int /* line */
139 #endif
140 #endif
141                                  );
142         void (*condition_broadcast)(
143 #if NeedNestedPrototypes
144                                  xcondition_t /* cv */
145 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
146                                  , char* /* file */,
147                                  int /* line */
148 #endif
149 #endif
150                                     );
151         /* used in XlibInt.c and XLockDis.c */
152         void (*lock_wait)(
153 #if NeedNestedPrototypes
154                           Display* /* dpy */
155 #endif
156                           );
157         void (*user_lock_display)(
158 #if NeedNestedPrototypes
159                                   Display* /* dpy */
160 #endif
161                                   );
162         void (*user_unlock_display)(
163 #if NeedNestedPrototypes
164                                     Display* /* dpy */
165 #endif
166                                     );
167         struct _XCVList *(*create_cvl)(
168 #if NeedNestedPrototypes
169                                        Display * /* dpy */
170 #endif
171                                        );
172 };
173
174 #define UnlockNextEventReader(d) if ((d)->lock) \
175     (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail)
176
177 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
178 #define ConditionWait(d,c) if ((d)->lock) \
179         (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__)
180 #define ConditionSignal(d,c) if ((d)->lock) \
181         (*(d)->lock->condition_signal)(c,__FILE__,__LINE__)
182 #define ConditionBroadcast(d,c) if ((d)->lock) \
183         (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__)
184 #else
185 #define ConditionWait(d,c) if ((d)->lock) \
186         (*(d)->lock->condition_wait)(c, (d)->lock->mutex)
187 #define ConditionSignal(d,c) if ((d)->lock) \
188         (*(d)->lock->condition_signal)(c)
189 #define ConditionBroadcast(d,c) if ((d)->lock) \
190         (*(d)->lock->condition_broadcast)(c)
191 #endif
192
193 typedef struct _LockInfoRec {
194         xmutex_t        lock;
195 } LockInfoRec;
196
197 #endif /* _X_locking_H_ */