Move c->out.vec refs out of _xcb_conn_wait up to _xcb_out_flush.
[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 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #ifdef GCC_HAS_VISIBILITY
36 #pragma GCC visibility push(hidden)
37 #endif
38
39 enum workarounds {
40     WORKAROUND_NONE,
41     WORKAROUND_GLX_GET_FB_CONFIGS_BUG
42 };
43
44 #define XCB_PAD(i) (-(i) & 3)
45
46 /* xcb_list.c */
47
48 typedef void (*XCBListFreeFunc)(void *);
49
50 typedef struct _xcb_map _xcb_map;
51
52 _xcb_map *_xcb_map_new(void);
53 void _xcb_map_delete(_xcb_map *q, XCBListFreeFunc do_free);
54 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
55 void *_xcb_map_remove(_xcb_map *q, unsigned int key);
56
57
58 /* xcb_out.c */
59
60 typedef struct _xcb_out {
61     pthread_cond_t cond;
62     int writing;
63
64     char queue[4096];
65     int queue_len;
66     struct iovec *vec;
67     int vec_len;
68
69     unsigned int request;
70     unsigned int request_written;
71
72     pthread_mutex_t reqlenlock;
73     CARD32 maximum_request_length;
74 } _xcb_out;
75
76 int _xcb_out_init(_xcb_out *out);
77 void _xcb_out_destroy(_xcb_out *out);
78
79 int _xcb_out_write(XCBConnection *c, struct iovec **vector, int *count);
80 int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count);
81 int _xcb_out_flush(XCBConnection *c);
82
83
84 /* xcb_in.c */
85
86 typedef struct _xcb_in {
87     pthread_cond_t event_cond;
88     int reading;
89
90     char queue[4096];
91     int queue_len;
92
93     unsigned int request_expected;
94     unsigned int request_read;
95     unsigned int request_completed;
96     struct reply_list *current_reply;
97     struct reply_list **current_reply_tail;
98
99     _xcb_map *replies;
100     struct event_list *events;
101     struct event_list **events_tail;
102     struct reader_list *readers;
103
104     struct pending_reply *pending_replies;
105     struct pending_reply **pending_replies_tail;
106 } _xcb_in;
107
108 int _xcb_in_init(_xcb_in *in);
109 void _xcb_in_destroy(_xcb_in *in);
110
111 int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workarounds workaround, int flags);
112
113 int _xcb_in_read(XCBConnection *c);
114 int _xcb_in_read_block(XCBConnection *c, void *buf, int nread);
115
116
117 /* xcb_xid.c */
118
119 typedef struct _xcb_xid {
120     pthread_mutex_t lock;
121     CARD32 last;
122     CARD32 base;
123     CARD32 max;
124     CARD32 inc;
125 } _xcb_xid;
126
127 int _xcb_xid_init(XCBConnection *c);
128 void _xcb_xid_destroy(XCBConnection *c);
129
130
131 /* xcb_ext.c */
132
133 typedef struct _xcb_ext {
134     pthread_mutex_t lock;
135     struct lazyreply *extensions;
136     int extensions_size;
137 } _xcb_ext;
138
139 int _xcb_ext_init(XCBConnection *c);
140 void _xcb_ext_destroy(XCBConnection *c);
141
142
143 /* xcb_conn.c */
144
145 struct XCBConnection {
146     /* constant data */
147     XCBConnSetupSuccessRep *setup;
148     int fd;
149
150     /* I/O data */
151     pthread_mutex_t iolock;
152     _xcb_in in;
153     _xcb_out out;
154
155     /* misc data */
156     _xcb_ext ext;
157     _xcb_xid xid;
158 };
159
160 int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector, int *count);
161
162 #ifdef GCC_HAS_VISIBILITY
163 #pragma GCC visibility pop
164 #endif
165
166 #endif