From 7ebe7373e6b7d9ee7acfcc4616ef783362974fbc Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Tue, 2 Apr 2013 17:10:35 +0900 Subject: [PATCH] eina: make it possible to disable Eina_Cow GC at instantiation time. --- src/lib/edje/edje_main.c | 4 ++-- src/lib/eina/eina_cow.c | 18 +++++++++++------- src/lib/eina/eina_cow.h | 3 ++- src/lib/evas/canvas/evas_object_image.c | 9 ++++++--- src/lib/evas/canvas/evas_object_main.c | 6 +++--- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/lib/edje/edje_main.c b/src/lib/edje/edje_main.c index f8116b5..d94affe 100644 --- a/src/lib/edje/edje_main.c +++ b/src/lib/edje/edje_main.c @@ -98,8 +98,8 @@ edje_init(void) goto shutdown_all; } - _edje_calc_params_map_cow = eina_cow_add("Edje Calc Params Map", sizeof (Edje_Calc_Params), 8, &default_calc_map); - _edje_calc_params_physics_cow= eina_cow_add("Edje Calc Params Physics", sizeof (Edje_Calc_Params_Physics), 8, &default_calc_physics); + _edje_calc_params_map_cow = eina_cow_add("Edje Calc Params Map", sizeof (Edje_Calc_Params), 8, &default_calc_map, EINA_TRUE); + _edje_calc_params_physics_cow= eina_cow_add("Edje Calc Params Physics", sizeof (Edje_Calc_Params_Physics), 8, &default_calc_physics, EINA_TRUE); eina_log_timing(_edje_default_log_dom, EINA_LOG_STATE_STOP, diff --git a/src/lib/eina/eina_cow.c b/src/lib/eina/eina_cow.c index 4abe979..59cefc8 100644 --- a/src/lib/eina/eina_cow.c +++ b/src/lib/eina/eina_cow.c @@ -319,7 +319,7 @@ eina_cow_shutdown(void) } EAPI Eina_Cow * -eina_cow_add(const char *name, unsigned int struct_size, unsigned int step, const void *default_value) +eina_cow_add(const char *name, unsigned int struct_size, unsigned int step, const void *default_value, Eina_Bool gc) { const char *choice, *tmp; Eina_Cow *cow; @@ -362,7 +362,10 @@ eina_cow_add(const char *name, unsigned int struct_size, unsigned int step, cons NULL, 6); #endif - cow->togc = eina_hash_pointer_new(_eina_cow_gc_free); + if (gc) + cow->togc = eina_hash_pointer_new(_eina_cow_gc_free); + else + cow->togc = NULL; cow->default_value = default_value; cow->struct_size = struct_size; cow->total_size = total_size; @@ -389,8 +392,7 @@ eina_cow_del(Eina_Cow *cow) eina_mempool_del(cow->pool); eina_hash_free(cow->match); - eina_hash_free(cow->togc); - + if (cow->togc) eina_hash_free(cow->togc); free(cow); } @@ -542,7 +544,7 @@ eina_cow_done(Eina_Cow *cow, VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref)); #endif - if (!needed_gc) return ; + if (!cow->togc || !needed_gc) return ; #ifndef NVALGRIND VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref)); @@ -572,7 +574,8 @@ eina_cow_memcpy(Eina_Cow *cow, EINA_COW_PTR_MAGIC_CHECK(ref); ref->refcount++; - _eina_cow_togc_del(cow, ref); + if (cow->togc) + _eina_cow_togc_del(cow, ref); #ifndef NVALGRIND VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref)); @@ -595,7 +598,8 @@ eina_cow_gc(Eina_Cow *cow) EINA_COW_MAGIC_CHECK(cow); - if (!eina_hash_population(cow->togc)) return EINA_FALSE; + if (!cow->togc || !eina_hash_population(cow->togc)) + return EINA_FALSE; it = eina_hash_iterator_data_new(cow->togc); r = eina_iterator_next(it, (void**) &gc); diff --git a/src/lib/eina/eina_cow.h b/src/lib/eina/eina_cow.h index 452dd28..875e1fe 100644 --- a/src/lib/eina/eina_cow.h +++ b/src/lib/eina/eina_cow.h @@ -58,9 +58,10 @@ typedef void Eina_Cow_Data; * @param struct_size The size of the object from this pool. * @param step How many object to allocate when the pool get empty. * @param default_value The default value returned by this pool. + * @param gc Is it possible to run the garbage collection on this pool. * @return a valid new Eina_Cow or @c NULL on error. */ -EAPI Eina_Cow *eina_cow_add(const char *name, unsigned int struct_size, unsigned int step, const void *default_value) EINA_WARN_UNUSED_RESULT; +EAPI Eina_Cow *eina_cow_add(const char *name, unsigned int struct_size, unsigned int step, const void *default_value, Eina_Bool gc) EINA_WARN_UNUSED_RESULT; /** * @brief Destroy an Eina_Cow pool and all the allocated memory diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c index 2a0ca94..f9c7c0b 100644 --- a/src/lib/evas/canvas/evas_object_image.c +++ b/src/lib/evas/canvas/evas_object_image.c @@ -266,15 +266,18 @@ _init_cow(Eo *eo_obj) evas_object_image_load_opts_cow = eina_cow_add("Evas_Object_Image load opts", sizeof (Evas_Object_Image_Load_Opts), 8, - &default_load_opts); + &default_load_opts, + EINA_TRUE); evas_object_image_pixels_cow = eina_cow_add("Evas_Object_Image pixels", sizeof (Evas_Object_Image_Pixels), 8, - &default_pixels); + &default_pixels, + EINA_TRUE); evas_object_image_state_cow = eina_cow_add("Evas_Object_Image states", sizeof (Evas_Object_Image_State), 8, - &default_state); + &default_state, + EINA_TRUE); } if (!evas_object_image_load_opts_cow || !evas_object_image_pixels_cow || diff --git a/src/lib/evas/canvas/evas_object_main.c b/src/lib/evas/canvas/evas_object_main.c index 369d588..b7a0e11 100644 --- a/src/lib/evas/canvas/evas_object_main.c +++ b/src/lib/evas/canvas/evas_object_main.c @@ -46,9 +46,9 @@ _init_cow(void) { if (evas_object_map_cow && evas_object_proxy_cow && evas_object_state_cow) return EINA_TRUE; - evas_object_proxy_cow = eina_cow_add("Evas Object Proxy", sizeof (Evas_Object_Proxy_Data), 8, &default_proxy); - evas_object_map_cow = eina_cow_add("Evas Object Map", sizeof (Evas_Object_Map_Data), 8, &default_map); - evas_object_state_cow = eina_cow_add("Evas Object State", sizeof (Evas_Object_Protected_State), 64, &default_state); + evas_object_proxy_cow = eina_cow_add("Evas Object Proxy", sizeof (Evas_Object_Proxy_Data), 8, &default_proxy, EINA_TRUE); + evas_object_map_cow = eina_cow_add("Evas Object Map", sizeof (Evas_Object_Map_Data), 8, &default_map, EINA_TRUE); + evas_object_state_cow = eina_cow_add("Evas Object State", sizeof (Evas_Object_Protected_State), 64, &default_state, EINA_FALSE); if (!(evas_object_map_cow && evas_object_proxy_cow && evas_object_state_cow)) { -- 2.7.4