#include <assert.h>
#include <fcntl.h>
#include <sys/poll.h>
+#include <pthread.h>
#include "wayland-util.h"
#include "wayland-os.h"
struct wl_map objects;
struct wl_list global_listener_list;
struct wl_list global_list;
+ pthread_mutex_t mutex;
wl_display_global_func_t global_handler;
void *global_handler_data;
proxy->object.interface = interface;
proxy->object.implementation = NULL;
+ proxy->display = display;
+
+ pthread_mutex_lock(&display->mutex);
proxy->object.id = wl_map_insert_new(&display->objects,
WL_MAP_CLIENT_SIDE, proxy);
- proxy->display = display;
+ pthread_mutex_unlock(&display->mutex);
return proxy;
}
proxy->object.implementation = NULL;
proxy->object.id = id;
proxy->display = display;
+
+ pthread_mutex_lock(&display->mutex);
wl_map_insert_at(&display->objects, id, proxy);
+ pthread_mutex_unlock(&display->mutex);
return proxy;
}
WL_EXPORT void
wl_proxy_destroy(struct wl_proxy *proxy)
{
+ pthread_mutex_lock(&proxy->display->mutex);
+
if (proxy->object.id < WL_SERVER_ID_START)
wl_map_insert_at(&proxy->display->objects,
proxy->object.id, WL_ZOMBIE_OBJECT);
else
wl_map_insert_at(&proxy->display->objects,
proxy->object.id, NULL);
+
+ pthread_mutex_unlock(&proxy->display->mutex);
+
free(proxy);
}
struct wl_closure *closure;
va_list ap;
+ pthread_mutex_lock(&proxy->display->mutex);
+
va_start(ap, opcode);
closure = wl_closure_vmarshal(&proxy->object, opcode, ap,
&proxy->object.interface->methods[opcode]);
}
wl_closure_destroy(closure);
+
+ pthread_mutex_unlock(&proxy->display->mutex);
}
/* Can't do this, there may be more than one instance of an
{
struct wl_proxy *proxy;
+ pthread_mutex_lock(&display->mutex);
+
proxy = wl_map_lookup(&display->objects, id);
if (proxy != WL_ZOMBIE_OBJECT)
fprintf(stderr, "server sent delete_id for live object\n");
else
wl_map_remove(&display->objects, id);
+
+ pthread_mutex_unlock(&display->mutex);
}
static const struct wl_display_listener display_listener = {
id = closure->buffer[0];
opcode = closure->buffer[1] & 0xffff;
+ pthread_mutex_lock(&display->mutex);
proxy = wl_map_lookup(&display->objects, id);
+ pthread_mutex_unlock(&display->mutex);
+
if (proxy == WL_ZOMBIE_OBJECT)
goto skip;
struct wl_closure *closure;
int len, size;
+ pthread_mutex_lock(&display->mutex);
+
/* FIXME: Handle flush errors, EAGAIN... */
- wl_display_flush(display);
+ wl_connection_flush(display->connection);
/* FIXME: Shouldn't always read here... */
len = wl_connection_read(display->connection);
- if (len == -1)
+ if (len == -1) {
+ pthread_mutex_unlock(&display->mutex);
return -1;
+ }
wl_list_init(&list);
while (len >= 8) {
len -= size;
}
+ pthread_mutex_unlock(&display->mutex);
+
while (!wl_list_empty(&list)) {
closure = container_of(list.next, struct wl_closure, link);
dispatch_event(display, closure);
WL_EXPORT int
wl_display_flush(struct wl_display *display)
{
- return wl_connection_flush(display->connection);
+ int ret;
+
+ pthread_mutex_lock(&display->mutex);
+
+ ret = wl_connection_flush(display->connection);
+
+ pthread_mutex_unlock(&display->mutex);
+
+ return ret;
}
WL_EXPORT void *