summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@free.fr>2019-09-14 10:54:05 -0700
committerCedric Bail <cedric.bail@free.fr>2019-09-19 14:37:41 -0700
commit9382bfc0bc1c6a5fb3aafce18094016b110036c0 (patch)
treed829f299356af2136ed3144887cb40b2f0dc884f /src/lib/eina
parentbf12fe241ec04c81129faf9ccfa7438fa9a23062 (diff)
eina: add eina_mempool_iterator_new to slowly iterate every allocated pointer in a mempool.
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D9941
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_inline_mempool.x13
-rw-r--r--src/lib/eina/eina_mempool.c1
-rw-r--r--src/lib/eina/eina_mempool.h11
3 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/eina/eina_inline_mempool.x b/src/lib/eina/eina_inline_mempool.x
index d30364f..0805c82 100644
--- a/src/lib/eina/eina_inline_mempool.x
+++ b/src/lib/eina/eina_inline_mempool.x
@@ -56,6 +56,11 @@ struct _Eina_Mempool_Backend
56 * @see eina_mempool_from 56 * @see eina_mempool_from
57 */ 57 */
58 Eina_Bool (*from)(void *data, void *element); 58 Eina_Bool (*from)(void *data, void *element);
59 /** Function to get an Eina_Iterator that will walk every allocated element
60 * in the pool.
61 * @use eina_mempool_iterator_new
62 */
63 Eina_Iterator *(*iterator)(void *data);
59}; 64};
60 65
61struct _Eina_Mempool_Backend_ABI1 66struct _Eina_Mempool_Backend_ABI1
@@ -74,6 +79,7 @@ struct _Eina_Mempool_Backend_ABI2
74{ 79{
75 void (*repack)(void *data, Eina_Mempool_Repack_Cb cb, void *cb_data); 80 void (*repack)(void *data, Eina_Mempool_Repack_Cb cb, void *cb_data);
76 Eina_Bool (*from)(void *data, void *element); 81 Eina_Bool (*from)(void *data, void *element);
82 Eina_Iterator *(*iterator)(void *data);
77}; 83};
78 84
79struct _Eina_Mempool 85struct _Eina_Mempool
@@ -116,6 +122,13 @@ eina_mempool_from(Eina_Mempool *mp, void *element)
116 return mp->backend2->from(mp->backend_data, element); 122 return mp->backend2->from(mp->backend_data, element);
117} 123}
118 124
125static inline Eina_Iterator *
126eina_mempool_iterator_new(Eina_Mempool *mp)
127{
128 if (!mp->backend2->iterator) return NULL;
129 return mp->backend2->iterator(mp->backend_data);
130}
131
119static inline unsigned int 132static inline unsigned int
120eina_mempool_alignof(unsigned int size) 133eina_mempool_alignof(unsigned int size)
121{ 134{
diff --git a/src/lib/eina/eina_mempool.c b/src/lib/eina/eina_mempool.c
index 56144a0..51a2990 100644
--- a/src/lib/eina/eina_mempool.c
+++ b/src/lib/eina/eina_mempool.c
@@ -104,6 +104,7 @@ _new_va(const char *name,
104 if (!mp->backend2) goto on_error; 104 if (!mp->backend2) goto on_error;
105 mp->backend2->repack = be->repack; 105 mp->backend2->repack = be->repack;
106 mp->backend2->from = be->from; 106 mp->backend2->from = be->from;
107 mp->backend2->iterator = be->iterator;
107 } 108 }
108 109
109 mp->backend_data = mp->backend.init(context, options, args); 110 mp->backend_data = mp->backend.init(context, options, args);
diff --git a/src/lib/eina/eina_mempool.h b/src/lib/eina/eina_mempool.h
index 606ecba..d7759ce 100644
--- a/src/lib/eina/eina_mempool.h
+++ b/src/lib/eina/eina_mempool.h
@@ -198,6 +198,17 @@ static inline Eina_Bool eina_mempool_from(Eina_Mempool *mp, void *element);
198EAPI void eina_mempool_statistics(Eina_Mempool *mp) EINA_ARG_NONNULL(1); 198EAPI void eina_mempool_statistics(Eina_Mempool *mp) EINA_ARG_NONNULL(1);
199 199
200/** 200/**
201 * @brief Provide an iterator to walk all allocated elements from a specified mempool.
202 *
203 * @param[in] mp The mempool
204 * @return @c NULL if it is not possible to iterate over the mempool, a valid iterator otherwise.
205 *
206 * @note This call is expected to be slow and should not be used in any performance critical area.
207 * @since 1.23
208 */
209static inline Eina_Iterator *eina_mempool_iterator_new(Eina_Mempool *mp);
210
211/**
201 * @brief Registers the given memory pool backend. 212 * @brief Registers the given memory pool backend.
202 * 213 *
203 * @param[in] be The backend 214 * @param[in] be The backend