[libvirt] [libvirt-glib 4/5] mainloop: protect 'handles' and 'timeouts' against concurrent accesses
Daniel P. Berrange
berrange at redhat.com
Mon Jun 25 10:00:36 UTC 2012
On Wed, Jun 20, 2012 at 12:29:50PM +0200, Christophe Fergeau wrote:
> Timeout and watch deletion is done from an idle callback. However,
> we cannot assume that all libvirt event calls (the callbacks passed
> to virEventRegisterImpl) will be done from the mainloop thread. It's
> thus possible that a libvirt event call will run a thread while
> one of the idle deletion callbacks runs.
> Given that the 'handles' and 'timeouts' arrays are shared among all
> threads, we need to make sure we hold the 'eventlock' mutex before
> modifying them.
> ---
> libvirt-glib/libvirt-glib-event.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
> index c2eeb7a..587a59e 100644
> --- a/libvirt-glib/libvirt-glib-event.c
> +++ b/libvirt-glib/libvirt-glib-event.c
> @@ -255,11 +255,15 @@ _event_handle_remove(gpointer data)
> {
> struct gvir_event_handle *h = data;
>
> + g_mutex_lock(eventlock);
> +
> if (h->ff)
> (h->ff)(h->opaque);
>
> g_ptr_array_remove_fast(handles, h);
>
> + g_mutex_unlock(eventlock);
> +
> return FALSE;
> }
>
> @@ -404,11 +408,15 @@ _event_timeout_remove(gpointer data)
> {
> struct gvir_event_timeout *t = data;
>
> + g_mutex_lock(eventlock);
> +
> if (t->ff)
> (t->ff)(t->opaque);
>
> g_ptr_array_remove_fast(timeouts, t);
>
> + g_mutex_unlock(eventlock);
> +
> return FALSE;
> }
ACK, clear thread safety bug
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list