return 1;
}
+static int _xcb_xlib_init(_xcb_xlib *xlib)
+{
+ xlib->lock = 0;
+ pthread_cond_init(&xlib->cond, 0);
+ return 1;
+}
+
+static void _xcb_xlib_destroy(_xcb_xlib *xlib)
+{
+ pthread_cond_destroy(&xlib->cond);
+}
+
static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
{
static const char pad[3];
if(!(
set_fd_flags(fd) &&
pthread_mutex_init(&c->iolock, 0) == 0 &&
+ _xcb_xlib_init(&c->xlib) &&
_xcb_in_init(&c->in) &&
_xcb_out_init(&c->out) &&
write_setup(c, auth_info) &&
close(c->fd);
pthread_mutex_destroy(&c->iolock);
+ _xcb_xlib_destroy(&c->xlib);
_xcb_in_destroy(&c->in);
_xcb_out_destroy(&c->out);
void _xcb_lock_io(xcb_connection_t *c)
{
pthread_mutex_lock(&c->iolock);
+ while(c->xlib.lock)
+ {
+ if(pthread_equal(c->xlib.thread, pthread_self()))
+ break;
+ pthread_cond_wait(&c->xlib.cond, &c->iolock);
+ }
}
void _xcb_unlock_io(xcb_connection_t *c)
#include "xcbxlib.h"
#include "xcbint.h"
+#include <assert.h>
+
unsigned int xcb_get_request_sent(xcb_connection_t *c)
{
if(c->has_error)
return 0;
return &c->iolock;
}
+
+void xcb_xlib_lock(xcb_connection_t *c)
+{
+ _xcb_lock_io(c);
+ assert(!c->xlib.lock);
+ c->xlib.lock = 1;
+ c->xlib.thread = pthread_self();
+ _xcb_unlock_io(c);
+}
+
+void xcb_xlib_unlock(xcb_connection_t *c)
+{
+ _xcb_lock_io(c);
+ assert(c->xlib.lock);
+ assert(pthread_equal(c->xlib.thread, pthread_self()));
+ c->xlib.lock = 0;
+ pthread_cond_broadcast(&c->xlib.cond);
+ _xcb_unlock_io(c);
+}
int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread);
+/* xcb_xlib.c */
+
+typedef struct _xcb_xlib {
+ int lock;
+ pthread_t thread;
+ pthread_cond_t cond;
+} _xcb_xlib;
+
+
/* xcb_xid.c */
typedef struct _xcb_xid {
/* I/O data */
pthread_mutex_t iolock;
+ _xcb_xlib xlib;
_xcb_in in;
_xcb_out out;
};
void _xcb_conn_shutdown(xcb_connection_t *c);
-void _xcb_lock_io(xcb_connection_t *c);
-void _xcb_unlock_io(xcb_connection_t *c);
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
#pragma GCC visibility pop
#endif
+
+/* xcb_conn.c symbols visible to xcb-xlib */
+
+void _xcb_lock_io(xcb_connection_t *c);
+void _xcb_unlock_io(xcb_connection_t *c);
+
#endif
pthread_mutex_t *xcb_get_io_lock(xcb_connection_t *c);
+void xcb_xlib_lock(xcb_connection_t *c);
+void xcb_xlib_unlock(xcb_connection_t *c);
+
#endif