Split the global registry into its own wl_registry object

The only way to make the global object listener interface thread safe is to
make it its own interface and make different listeners different wl_proxies.
The core of the problem is the callback we do when a global show up or
disappears, which we can't do with a lock held.  On the other hand we can't
iterate the global list or the listener list without a lock held as new
globals or listeners may come and go during the iteration.

Making a copy of the list under the lock and then iterating after dropping
the lock wont work either.  In case of the listener list, once we drop the
lock another thread may unregister a listener and destroy the callbackk
data, which means that when we eventually call that listener we'll pass it
free memory and break everything.

We did already solve the thread-safe callback problem, however.  It's what
we do for all protocol events.  So we can just make the global registry
functionality its own new interface and give each thread its own proxy.
That way, the thread will do its own callbacks (with no locks held) and
destroy the proxy when it's no longer interested in wl_registry events.
This commit is contained in:
Kristian Høgsberg 2012-10-08 13:53:47 -04:00
parent 8872956dfd
commit 9fe75537ad
4 changed files with 72 additions and 162 deletions

View file

@ -32,14 +32,6 @@
The core global object. This is a special singleton object. It
is used for internal Wayland protocol features.
</description>
<request name="bind">
<description summary="bind an object to the display">
Binds a new, client-created object to the server using @name as
the identifier.
</description>
<arg name="name" type="uint" summary="unique number id for object"/>
<arg name="id" type="new_id"/>
</request>
<request name="sync">
<description summary="asynchronous roundtrip">
@ -51,6 +43,10 @@
<arg name="callback" type="new_id" interface="wl_callback"/>
</request>
<request name="get_registry">
<arg name="callback" type="new_id" interface="wl_registry"/>
</request>
<event name="error">
<description summary="fatal error event">
The error event is sent out when a fatal (non-recoverable)
@ -74,6 +70,24 @@
summary="server is out of memory"/>
</enum>
<event name="delete_id">
<description summary="acknowledge object id deletion">
Server has deleted the id and client can now reuse it.
</description>
<arg name="id" type="uint" />
</event>
</interface>
<interface name="wl_registry" version="1">
<request name="bind">
<description summary="bind an object to the display">
Binds a new, client-created object to the server using @name as
the identifier.
</description>
<arg name="name" type="uint" summary="unique number id for object"/>
<arg name="id" type="new_id"/>
</request>
<event name="global">
<description summary="announce global object">
Notify the client of global objects. These are objects that
@ -96,13 +110,6 @@
</description>
<arg name="name" type="uint"/>
</event>
<event name="delete_id">
<description summary="acknowledge object id deletion">
Server has deleted the id and client can now reuse it.
</description>
<arg name="id" type="uint" />
</event>
</interface>
<interface name="wl_callback" version="1">