client: Keep track of proxy validity and number of reference holders
authorJonas Ådahl <jadahl@gmail.com>
Sat, 3 Nov 2012 21:26:10 +0000 (22:26 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Mon, 5 Nov 2012 20:44:50 +0000 (15:44 -0500)
commite273c7cde34c23437d34732082d46aee537f6611
treef0daa68ad8224698a465e025b4b345f586e39e32
parentc4857e92321e85afe40fb66902cdddc14fbae05a
client: Keep track of proxy validity and number of reference holders

When events are queued, the associated proxy objects (target proxy and
potentially closure argument proxies) are verified being valid. However,
as any event may destroy some proxy object, validity needs to be
verified again before dispatching. Before this change this was done by
again looking up the object via the display object map, but that did not
work because a delete_id event could be dispatched out-of-order if it
was queued in another queue, causing the object map to either have a new
proxy object with the same id or none at all, had it been destroyed in
an earlier event in the queue.

Instead, make wl_proxy reference counted and increase the reference
counter of every object associated with an event when it is queued. In
wl_proxy_destroy() set a flag saying the proxy has been destroyed by the
application and only free the proxy if the reference counter reaches
zero after decreasing it.

Before dispatching, verify that a proxy object still is valid by
checking that the flag set in wl_proxy_destroy() has not been set. When
dequeuing the event, all associated proxy objects are dereferenced and
free:ed if the reference counter reaches zero. As proxy reference counter
is initiated to 1, when dispatching an event it can never reach zero
without having the destroyed flag set.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
src/wayland-client.c
src/wayland-private.h