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