Remove vestiges of adjacent request combining implementation. It is very dead.
[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 /* Not simply (a <= b) because eventually the 32-bit sequence number
32  * will wrap, causing earlier sequence numbers to be higher than later
33  * ones for a brief but fatal period. (a and b must be unsigned.) */
34 #define _xcb_assert_sequence_less(a,b) assert((b) - (a) < 65536)
35
36 #define _xcb_assert_valid_sequence(c) do { \
37     _xcb_assert_sequence_less((c)->in.request_read, (c)->out.request_written); \
38     _xcb_assert_sequence_less((c)->out.request_written, (c)->out.request); \
39 } while(0)
40
41 enum workarounds {
42     WORKAROUND_NONE,
43     WORKAROUND_GLX_GET_FB_CONFIGS_BUG
44 };
45
46 /* xcb_list.c */
47
48 typedef struct _xcb_list _xcb_list;
49 typedef void (*XCBListFreeFunc)(void *);
50
51 _xcb_list *_xcb_list_new(void);
52 void _xcb_list_delete(_xcb_list *list, XCBListFreeFunc do_free);
53 int _xcb_list_insert(_xcb_list *list, void *data);
54 int _xcb_list_append(_xcb_list *list, void *data);
55 void *_xcb_list_peek_head(_xcb_list *list);
56 void *_xcb_list_remove_head(_xcb_list *list);
57 void *_xcb_list_remove(_xcb_list *list, int (*cmp)(const void *, const void *), const void *data);
58 void *_xcb_list_find(_xcb_list *list, int (*cmp)(const void *, const void *), const void *data);
59
60 typedef _xcb_list _xcb_queue;
61
62 _xcb_queue *_xcb_queue_new(void);
63 void _xcb_queue_delete(_xcb_queue *q, XCBListFreeFunc do_free);
64 int _xcb_queue_enqueue(_xcb_queue *q, void *data);
65 void *_xcb_queue_dequeue(_xcb_queue *q);
66 int _xcb_queue_is_empty(_xcb_queue *q);
67
68 typedef _xcb_list _xcb_map;
69
70 _xcb_map *_xcb_map_new(void);
71 void _xcb_map_delete(_xcb_map *q, XCBListFreeFunc do_free);
72 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
73 void *_xcb_map_get(_xcb_map *q, unsigned int key);
74 void *_xcb_map_remove(_xcb_map *q, unsigned int key);
75
76
77 /* xcb_util.c */
78
79 /* Index of nearest 4-byte boundary following E. */
80 #define XCB_CEIL(E) (((E)+3)&~3)
81
82 #define XCB_PAD(i) ((4 - (i & 3)) & 3)
83
84 int _xcb_set_fd_flags(const int fd);
85 int _xcb_readn(const int fd, void *buf, const int buflen, int *count);
86 int _xcb_read_block(const int fd, void *buf, const size_t len);
87 int _xcb_write(const int fd, char (*buf)[], int *count);
88 int _xcb_writev(const int fd, struct iovec *vec, int count);
89
90
91 /* xcb_out.c */
92
93 typedef struct _xcb_out {
94     pthread_cond_t cond;
95     int writing;
96
97     char queue[4096];
98     int queue_len;
99     struct iovec *vec;
100     int vec_len;
101
102     unsigned int request;
103     unsigned int request_written;
104
105     pthread_mutex_t reqlenlock;
106     CARD32 maximum_request_length;
107 } _xcb_out;
108
109 int _xcb_out_init(_xcb_out *out);
110 void _xcb_out_destroy(_xcb_out *out);
111
112 int _xcb_out_write(XCBConnection *c);
113 int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count);
114 int _xcb_out_flush(XCBConnection *c);
115
116
117 /* xcb_in.c */
118
119 typedef struct _xcb_in {
120     pthread_cond_t event_cond;
121     int reading;
122
123     char queue[4096];
124     int queue_len;
125
126     unsigned int request_read;
127     _xcb_queue *current_reply;
128
129     _xcb_map *replies;
130     _xcb_queue *events;
131     _xcb_list *readers;
132
133     _xcb_queue *pending_replies;
134 } _xcb_in;
135
136 int _xcb_in_init(_xcb_in *in);
137 void _xcb_in_destroy(_xcb_in *in);
138
139 int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workarounds workaround);
140
141 int _xcb_in_read_packet(XCBConnection *c);
142 int _xcb_in_read(XCBConnection *c);
143 int _xcb_in_read_block(XCBConnection *c, void *buf, int nread);
144
145
146 /* xcb_xid.c */
147
148 typedef struct _xcb_xid {
149     pthread_mutex_t lock;
150     CARD32 last;
151     CARD32 base;
152     CARD32 max;
153     CARD32 inc;
154 } _xcb_xid;
155
156 int _xcb_xid_init(XCBConnection *c);
157 void _xcb_xid_destroy(XCBConnection *c);
158
159
160 /* xcb_ext.c */
161
162 typedef struct _xcb_ext {
163     pthread_mutex_t lock;
164     _xcb_map *extensions;
165 } _xcb_ext;
166
167 int _xcb_ext_init(XCBConnection *c);
168 void _xcb_ext_destroy(XCBConnection *c);
169
170
171 /* xcb_conn.c */
172
173 struct XCBConnection {
174     /* constant data */
175     XCBConnSetupSuccessRep *setup;
176     int fd;
177
178     /* I/O data */
179     pthread_mutex_t iolock;
180     _xcb_in in;
181     _xcb_out out;
182
183     /* misc data */
184     _xcb_ext ext;
185     _xcb_xid xid;
186 };
187
188 int _xcb_conn_wait(XCBConnection *c, const int should_write, pthread_cond_t *cond);
189 #endif