From 8683c6ecf6c66c4993c1816f8357d0cf016c4022 Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Fri, 9 Oct 2015 10:23:30 -0400 Subject: [PATCH] ecore-wl2: Implement reference counting for client connected displays Signed-off-by: Chris Michael --- src/lib/ecore_wl2/ecore_wl2_display.c | 34 +++++++++++++++++++++------------- src/lib/ecore_wl2/ecore_wl2_private.h | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/lib/ecore_wl2/ecore_wl2_display.c b/src/lib/ecore_wl2/ecore_wl2_display.c index 55e8a89..82c8453 100644 --- a/src/lib/ecore_wl2/ecore_wl2_display.c +++ b/src/lib/ecore_wl2/ecore_wl2_display.c @@ -288,6 +288,10 @@ _ecore_wl2_display_cleanup(Ecore_Wl2_Display *ewd) Ecore_Wl2_Input *input; Eina_Inlist *tmp; + if (--ewd->refs) return; + + if (ewd->xkb_context) xkb_context_unref(ewd->xkb_context); + /* free each input */ EINA_INLIST_FOREACH_SAFE(ewd->inputs, tmp, input) _ecore_wl2_input_del(input); @@ -296,15 +300,7 @@ _ecore_wl2_display_cleanup(Ecore_Wl2_Display *ewd) EINA_INLIST_FOREACH_SAFE(ewd->outputs, tmp, output) _ecore_wl2_output_del(output); - if (ewd->xkb_context) xkb_context_unref(ewd->xkb_context); - - if (ewd->idle_enterer) - { - /* remove this client display from hash */ - eina_hash_del(_client_displays, ewd->name, ewd); - - ecore_idle_enterer_del(ewd->idle_enterer); - } + if (ewd->idle_enterer) ecore_idle_enterer_del(ewd->idle_enterer); if (ewd->fd_hdl) ecore_main_fd_handler_del(ewd->fd_hdl); @@ -323,6 +319,9 @@ _ecore_wl2_display_cleanup(Ecore_Wl2_Display *ewd) wl_display_flush(ewd->wl.display); if (ewd->name) free(ewd->name); + + /* remove this client display from hash */ + eina_hash_del(_client_displays, ewd->name, ewd); } Ecore_Wl2_Window * @@ -423,7 +422,7 @@ ecore_wl2_display_connect(const char *name) /* check hash of cached client displays for this name */ ewd = eina_hash_find(_client_displays, n); - if (ewd) return ewd; + if (ewd) goto found; } } else @@ -432,13 +431,15 @@ ecore_wl2_display_connect(const char *name) /* check hash of cached client displays for this name */ ewd = eina_hash_find(_client_displays, name); - if (ewd) return ewd; + if (ewd) goto found; } /* allocate space for display structure */ ewd = calloc(1, sizeof(Ecore_Wl2_Display)); if (!ewd) return NULL; + ewd->refs++; + if (name) ewd->name = strdup(name); else if (n) @@ -491,6 +492,10 @@ connect_err: free(ewd->name); free(ewd); return NULL; + +found: + ewd->refs++; + return ewd; } EAPI void @@ -498,8 +503,11 @@ ecore_wl2_display_disconnect(Ecore_Wl2_Display *display) { EINA_SAFETY_ON_NULL_RETURN(display); _ecore_wl2_display_cleanup(display); - wl_display_disconnect(display->wl.display); - free(display); + if (display->refs <= 0) + { + wl_display_disconnect(display->wl.display); + free(display); + } } EAPI void diff --git a/src/lib/ecore_wl2/ecore_wl2_private.h b/src/lib/ecore_wl2/ecore_wl2_private.h index f7939e1..99857ca 100644 --- a/src/lib/ecore_wl2/ecore_wl2_private.h +++ b/src/lib/ecore_wl2/ecore_wl2_private.h @@ -47,6 +47,7 @@ extern int _ecore_wl2_log_dom; struct _Ecore_Wl2_Display { + int refs; char *name; struct -- 2.7.4