[PATCH 1/2] Properly dispose event sources and event loops

Kristian Hoegsberg hoegsberg at gmail.com
Wed Mar 28 20:02:21 PDT 2012


On Wed, Mar 28, 2012 at 10:36:09PM +0200, Jonas Ådahl wrote:
> Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

Very nice clean up, thanks.  I moved the inline variable declaration
in evdev_add_devices() (const char *sysname) up alongside const char
*path;  Other than that, applied as is

Kristian

> ---
>  src/compositor-drm.c |   10 +++++++---
>  src/compositor.c     |    4 ++++
>  src/evdev.c          |   22 +++++++++++++++++++---
>  src/tty.c            |    3 +++
>  4 files changed, 33 insertions(+), 6 deletions(-)
> 
> diff --git a/src/compositor-drm.c b/src/compositor-drm.c
> index 4305cd5..fd41676 100644
> --- a/src/compositor-drm.c
> +++ b/src/compositor-drm.c
> @@ -1431,15 +1431,19 @@ drm_destroy(struct weston_compositor *ec)
>  	struct drm_compositor *d = (struct drm_compositor *) ec;
>  	struct weston_input_device *input, *next;
>  
> +	wl_list_for_each_safe(input, next, &ec->input_device_list, link)
> +		evdev_input_destroy(input);
> +
> +	wl_event_source_remove(d->udev_drm_source);
> +	wl_event_source_remove(d->drm_source);
> +
>  	weston_compositor_shutdown(ec);
> +
>  	gbm_device_destroy(d->gbm);
>  	destroy_sprites(d);
>  	drmDropMaster(d->drm.fd);
>  	tty_destroy(d->tty);
>  
> -	wl_list_for_each_safe(input, next, &ec->input_device_list, link)
> -		evdev_input_destroy(input);
> -
>  	free(d);
>  }
>  
> diff --git a/src/compositor.c b/src/compositor.c
> index 47305cc..f9e1f23 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -2415,6 +2415,8 @@ weston_compositor_shutdown(struct weston_compositor *ec)
>  	struct weston_output *output, *next;
>  
>  	wl_event_source_remove(ec->idle_source);
> +	if (ec->input_loop_source)
> +		wl_event_source_remove(ec->input_loop_source);
>  
>  	if (ec->screenshooter)
>  		screenshooter_destroy(ec->screenshooter);
> @@ -2427,6 +2429,8 @@ weston_compositor_shutdown(struct weston_compositor *ec)
>  
>  	wl_array_release(&ec->vertices);
>  	wl_array_release(&ec->indices);
> +
> +	wl_event_loop_destroy(ec->input_loop);
>  }
>  
>  static int on_term_signal(int signal_number, void *data)
> diff --git a/src/evdev.c b/src/evdev.c
> index 5dbe6ac..993c6d8 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -35,6 +35,7 @@ struct evdev_input {
>  	struct weston_input_device base;
>  	struct wl_list devices_list;
>  	struct udev_monitor *udev_monitor;
> +	struct wl_event_source *udev_monitor_source;
>  	char *seat_id;
>  };
>  
> @@ -571,8 +572,11 @@ evdev_add_devices(struct udev *udev, struct weston_input_device *input_base)
>  		path = udev_list_entry_get_name(entry);
>  		device = udev_device_new_from_syspath(udev, path);
>  
> -		if (strncmp("event", udev_device_get_sysname(device), 5) != 0)
> +		const char *sysname = udev_device_get_sysname(device);
> +		if (strncmp("event", sysname, 5) != 0) {
> +			udev_device_unref(device);
>  			continue;
> +		}
>  
>  		device_added(device, input);
>  
> @@ -632,6 +636,7 @@ evdev_config_udev_monitor(struct udev *udev, struct evdev_input *master)
>  {
>  	struct wl_event_loop *loop;
>  	struct weston_compositor *c = master->base.compositor;
> +	int fd;
>  
>  	master->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
>  	if (!master->udev_monitor) {
> @@ -644,12 +649,19 @@ evdev_config_udev_monitor(struct udev *udev, struct evdev_input *master)
>  
>  	if (udev_monitor_enable_receiving(master->udev_monitor)) {
>  		fprintf(stderr, "udev: failed to bind the udev monitor\n");
> +		udev_monitor_unref(master->udev_monitor);
>  		return 0;
>  	}
>  
>  	loop = wl_display_get_event_loop(c->wl_display);
> -	wl_event_loop_add_fd(loop, udev_monitor_get_fd(master->udev_monitor),
> -			     WL_EVENT_READABLE, evdev_udev_handler, master);
> +	fd = udev_monitor_get_fd(master->udev_monitor);
> +	master->udev_monitor_source =
> +		wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
> +				     evdev_udev_handler, master);
> +	if (!master->udev_monitor_source) {
> +		udev_monitor_unref(master->udev_monitor);
> +		return 0;
> +	}
>  
>  	return 1;
>  }
> @@ -696,6 +708,10 @@ evdev_input_destroy(struct weston_input_device *input_base)
>  	struct evdev_input *input = (struct evdev_input *) input_base;
>  
>  	evdev_remove_devices(input_base);
> +
> +	udev_monitor_unref(input->udev_monitor);
> +	wl_event_source_remove(input->udev_monitor_source);
> +
>  	wl_list_remove(&input->base.link);
>  	free(input->seat_id);
>  	free(input);
> diff --git a/src/tty.c b/src/tty.c
> index 249f5bb..c5e9e8a 100644
> --- a/src/tty.c
> +++ b/src/tty.c
> @@ -221,6 +221,9 @@ tty_destroy(struct tty *tty)
>  		ioctl(tty->fd, VT_WAITACTIVE, tty->starting_vt);
>  	}
>  
> +	wl_event_source_remove(tty->input_source);
> +	wl_event_source_remove(tty->vt_source);
> +
>  	close(tty->fd);
>  
>  	free(tty);
> -- 
> 1.7.5.4
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list