summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-12-21 15:37:47 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-12-21 15:44:15 +0900
commitd5e88e4cf99a15005f8dbb25d784526ac050c5bd (patch)
treefb7f3ffacf30c33b72a8ec93fd016eba9c3ea205 /src/lib/eina
parentffefbe0718c4821b7beb886b7a3630a63e8fe54c (diff)
eina freeq - add ability to set freeval and add a final freeval
this allows environment variables to set the byte falue to fill a freeq item added to the queue and then another item to actually fill memory with just before the free function so memory content difference will tell you if its inside the free queue or already freed from it completely. if you set tyhe freed value to 0 this will not fill with a value just before free and leave the value as-is determined by the first fill pattern value.
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_freeq.c31
-rw-r--r--src/lib/eina/eina_freeq.h29
2 files changed, 47 insertions, 13 deletions
diff --git a/src/lib/eina/eina_freeq.c b/src/lib/eina/eina_freeq.c
index c1aff8925c..17459dc5ee 100644
--- a/src/lib/eina/eina_freeq.c
+++ b/src/lib/eina/eina_freeq.c
@@ -57,21 +57,29 @@ struct _Eina_FreeQ
57 57
58// ========================================================================= // 58// ========================================================================= //
59 59
60static Eina_FreeQ *_eina_freeq_main = NULL; 60static Eina_FreeQ *_eina_freeq_main = NULL;
61static int _eina_freeq_bypass = -1; 61static int _eina_freeq_bypass = -1;
62static unsigned int _eina_freeq_fillpat_max = ITEM_FILLPAT_MAX; 62static unsigned int _eina_freeq_fillpat_max = ITEM_FILLPAT_MAX;
63static unsigned char _eina_freeq_fillpat_val = 0x55; 63static unsigned char _eina_freeq_fillpat_val = 0x55;
64static int _eina_freeq_total_max = ITEM_TOTAL_MAX; 64static unsigned char _eina_freeq_fillpat_freed_val = 0x77;
65static size_t _eina_freeq_mem_max = ITEM_MEM_MAX; 65static int _eina_freeq_total_max = ITEM_TOTAL_MAX;
66static size_t _eina_freeq_mem_max = ITEM_MEM_MAX;
66 67
67// ========================================================================= // 68// ========================================================================= //
68 69
69static void 70static inline void
70_eina_freeq_fill_do(void *ptr, size_t size) 71_eina_freeq_fill_do(void *ptr, size_t size)
71{ 72{
72 if (ptr) memset(ptr, _eina_freeq_fillpat_val, size); 73 if (ptr) memset(ptr, _eina_freeq_fillpat_val, size);
73} 74}
74 75
76static inline void
77_eina_freeq_freed_fill_do(void *ptr, size_t size)
78{
79 if (_eina_freeq_fillpat_freed_val == 0) return;
80 if (ptr) memset(ptr, _eina_freeq_fillpat_freed_val, size);
81}
82
75static void 83static void
76_eina_freeq_fill_check(void *ptr, void (*free_func) (void *ptr), size_t size) 84_eina_freeq_fill_check(void *ptr, void (*free_func) (void *ptr), size_t size)
77{ 85{
@@ -94,7 +102,10 @@ _eina_freeq_free_do(void *ptr,
94 size_t size EINA_UNUSED) 102 size_t size EINA_UNUSED)
95{ 103{
96 if ((size < _eina_freeq_fillpat_max) && (size > 0)) 104 if ((size < _eina_freeq_fillpat_max) && (size > 0))
97 _eina_freeq_fill_check(ptr, free_func, size); 105 {
106 _eina_freeq_fill_check(ptr, free_func, size);
107 _eina_freeq_freed_fill_do(ptr, size);
108 }
98 free_func(ptr); 109 free_func(ptr);
99 return; 110 return;
100} 111}
@@ -172,6 +183,10 @@ eina_freeq_new(void)
172 if (s) _eina_freeq_total_max = atoi(s); 183 if (s) _eina_freeq_total_max = atoi(s);
173 s = getenv("EINA_FREEQ_MEM_MAX"); 184 s = getenv("EINA_FREEQ_MEM_MAX");
174 if (s) _eina_freeq_mem_max = atoi(s) * 1024; 185 if (s) _eina_freeq_mem_max = atoi(s) * 1024;
186 s = getenv("EINA_FREEQ_FILL");
187 if (s) _eina_freeq_fillpat_val = atoi(s);
188 s = getenv("EINA_FREEQ_FILL_FREED");
189 if (s) _eina_freeq_fillpat_freed_val = atoi(s);
175 } 190 }
176 fq = calloc(1, sizeof(Eina_FreeQ)); 191 fq = calloc(1, sizeof(Eina_FreeQ));
177 if (!fq) return NULL; 192 if (!fq) return NULL;
diff --git a/src/lib/eina/eina_freeq.h b/src/lib/eina/eina_freeq.h
index 11a0bcaf47..eacd3a0ca9 100644
--- a/src/lib/eina/eina_freeq.h
+++ b/src/lib/eina/eina_freeq.h
@@ -17,10 +17,11 @@
17 * 17 *
18 * For debugging and tuning you may set the following envrionment variables: 18 * For debugging and tuning you may set the following envrionment variables:
19 * 19 *
20 * EINA_FREEQ_BYPASS=1 20 * EINA_FREEQ_BYPASS=1/0
21 * 21 *
22 * Set this environment variable to immediately bypass the free queue and 22 * Set this environment variable to 1 to immediately bypass the free queue and
23 * have all items submitted free with their free function immediately. 23 * have all items submitted free with their free function immediately. Set
24 * it to 0 to force the free queue to work and delay freeing of items.
24 * Note that you can override this by setting count or mem max by 25 * Note that you can override this by setting count or mem max by
25 * eina_freeq_count_max_set() or eina_freeq_mem_max_set() which will 26 * eina_freeq_count_max_set() or eina_freeq_mem_max_set() which will
26 * disable bypass for that specific free queue. once bypass is disabled 27 * disable bypass for that specific free queue. once bypass is disabled
@@ -31,17 +32,35 @@
31 * This sets the maximum number of bytes to N an item in the free queue may 32 * This sets the maximum number of bytes to N an item in the free queue may
32 * be in size for the free queue to fill it with debugging values like 33 * be in size for the free queue to fill it with debugging values like
33 * 0x55 in every byte, to ensure you can see what memory has been freed 34 * 0x55 in every byte, to ensure you can see what memory has been freed
34 * or not when debugging in tools like gdb. 35 * or not when debugging in tools like gdb. Note that this value is
36 * actually one greater than the actual maximum, so if this is set to 100
37 * a memory blob of 100 bytes will not be filled but one of 99 bytes in
38 * size will be.
35 * 39 *
36 * EINA_FREEQ_TOTAL_MAX=N 40 * EINA_FREEQ_TOTAL_MAX=N
37 * 41 *
38 * This sets the maximum number of items allowed to N on a free queue by 42 * This sets the maximum number of items allowed to N on a free queue by
39 * default before it starts emptying the free queue out tomake room. 43 * default before it starts emptying the free queue out to make room.
40 * 44 *
41 * EINA_FREEQ_MEM_MAX=N 45 * EINA_FREEQ_MEM_MAX=N
42 * 46 *
43 * This sets the maximum total number of Kb (Kilobytes) of memory allowed 47 * This sets the maximum total number of Kb (Kilobytes) of memory allowed
44 * on a free queue by default to N Kb worth of data. 48 * on a free queue by default to N Kb worth of data.
49 *
50 * EINA_FREEQ_FILL=N
51 *
52 * This sets the buyte value to write to every byte of an allocation that
53 * is added to the free queue when it is added to mark the data as invalid.
54 * The default value is 0x55 (85). Memory is only filled if the size of
55 * the allocation is less than the max that you can adjust with
56 * EINA_FREEQ_FILL_MAX.
57 *
58 * EINA_FREEQ_FILL_FREED=N
59 *
60 * Memory just before it is actually passed to the free function to be freed
61 * will be filled with this pattern value in every byte. The default value
62 * is 0x77 (119). Memory is only filled if the size of the allocation is
63 * less than the max that you can adjust with EINA_FREEQ_FILL_MAX.
45 * 64 *
46 * @{ 65 * @{
47 * 66 *