Factor pthread_cond_wait(iolock) to _xcb_wait_io.
[free-sw/xcb/libxcb] / src / xcbint.h
1 /*
2  * Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  * 
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  * 
22  * Except as contained in this notice, the names of the authors or their
23  * institutions shall not be used in advertising or otherwise to promote the
24  * sale, use or other dealings in this Software without prior written
25  * authorization from the authors.
26  */
27
28 #ifndef __XCBINT_H
29 #define __XCBINT_H
30
31 #include "bigreq.h"
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36
37 #ifdef GCC_HAS_VISIBILITY
38 #pragma GCC visibility push(hidden)
39 #endif
40
41 enum workarounds {
42     WORKAROUND_NONE,
43     WORKAROUND_GLX_GET_FB_CONFIGS_BUG
44 };
45
46 enum lazy_reply_tag
47 {
48     LAZY_NONE = 0,
49     LAZY_COOKIE,
50     LAZY_FORCED
51 };
52
53 #define XCB_PAD(i) (-(i) & 3)
54
55 #define XCB_SEQUENCE_COMPARE(a,op,b)    ((int) ((a) - (b)) op 0)
56
57 /* xcb_list.c */
58
59 typedef void (*xcb_list_free_func_t)(void *);
60
61 typedef struct _xcb_map _xcb_map;
62
63 _xcb_map *_xcb_map_new(void);
64 void _xcb_map_delete(_xcb_map *q, xcb_list_free_func_t do_free);
65 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
66 void *_xcb_map_remove(_xcb_map *q, unsigned int key);
67
68
69 /* xcb_out.c */
70
71 typedef struct _xcb_out {
72     pthread_cond_t cond;
73     int writing;
74
75     char queue[4096];
76     int queue_len;
77
78     unsigned int request;
79     unsigned int request_written;
80
81     pthread_mutex_t reqlenlock;
82     enum lazy_reply_tag maximum_request_length_tag;
83     union {
84         xcb_big_requests_enable_cookie_t cookie;
85         uint32_t value;
86     } maximum_request_length;
87 } _xcb_out;
88
89 int _xcb_out_init(_xcb_out *out);
90 void _xcb_out_destroy(_xcb_out *out);
91
92 int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count);
93 int _xcb_out_flush_to(xcb_connection_t *c, unsigned int request);
94
95
96 /* xcb_in.c */
97
98 typedef struct _xcb_in {
99     pthread_cond_t event_cond;
100     int reading;
101
102     char queue[4096];
103     int queue_len;
104
105     unsigned int request_expected;
106     unsigned int request_read;
107     unsigned int request_completed;
108     struct reply_list *current_reply;
109     struct reply_list **current_reply_tail;
110
111     _xcb_map *replies;
112     struct event_list *events;
113     struct event_list **events_tail;
114     struct reader_list *readers;
115
116     struct pending_reply *pending_replies;
117     struct pending_reply **pending_replies_tail;
118 } _xcb_in;
119
120 int _xcb_in_init(_xcb_in *in);
121 void _xcb_in_destroy(_xcb_in *in);
122
123 int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags);
124
125 int _xcb_in_read(xcb_connection_t *c);
126 int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread);
127
128
129 /* xcb_xlib.c */
130
131 typedef struct _xcb_xlib {
132     int lock;
133     int sloppy_lock;
134     pthread_t thread;
135     pthread_cond_t cond;
136 } _xcb_xlib;
137
138
139 /* xcb_xid.c */
140
141 typedef struct _xcb_xid {
142     pthread_mutex_t lock;
143     uint32_t last;
144     uint32_t base;
145     uint32_t max;
146     uint32_t inc;
147 } _xcb_xid;
148
149 int _xcb_xid_init(xcb_connection_t *c);
150 void _xcb_xid_destroy(xcb_connection_t *c);
151
152
153 /* xcb_ext.c */
154
155 typedef struct _xcb_ext {
156     pthread_mutex_t lock;
157     struct lazyreply *extensions;
158     int extensions_size;
159 } _xcb_ext;
160
161 int _xcb_ext_init(xcb_connection_t *c);
162 void _xcb_ext_destroy(xcb_connection_t *c);
163
164
165 /* xcb_conn.c */
166
167 struct xcb_connection_t {
168     int has_error;
169
170     /* constant data */
171     xcb_setup_t *setup;
172     int fd;
173
174     /* I/O data */
175     pthread_mutex_t iolock;
176     _xcb_xlib xlib;
177     _xcb_in in;
178     _xcb_out out;
179
180     /* misc data */
181     _xcb_ext ext;
182     _xcb_xid xid;
183 };
184
185 void _xcb_conn_shutdown(xcb_connection_t *c);
186 void _xcb_wait_io(xcb_connection_t *c, pthread_cond_t *cond);
187 int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
188
189
190 /* xcb_auth.c */
191
192 int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display);
193
194 #ifdef GCC_HAS_VISIBILITY
195 #pragma GCC visibility pop
196 #endif
197
198
199 /* xcb_conn.c symbols visible to xcb-xlib */
200
201 void _xcb_lock_io(xcb_connection_t *c);
202 void _xcb_unlock_io(xcb_connection_t *c);
203
204 #endif