summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-12-19 16:25:38 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-12-20 12:42:33 -0800
commitce56f32270c2f75adab022b701d3bdcbbbc3fb44 (patch)
treef66dc8bab0fd9ce7456d55ab96729ed9bc0283f4 /src/lib/eina
parent1305f28bc1a96b9001a3cd88f1a23f8aa3bf59f9 (diff)
eina: add a function to free Eina_Promise attached data when the promise is destroyed.
Reviewed-by: Lauro Neto <Lauro Moura <lauromoura@expertisesolutions.com.br>> Differential Revision: https://phab.enlightenment.org/D7491
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_promise.c21
-rw-r--r--src/lib/eina/eina_promise.h8
2 files changed, 26 insertions, 3 deletions
diff --git a/src/lib/eina/eina_promise.c b/src/lib/eina/eina_promise.c
index 222f7d5613..c239ba6261 100644
--- a/src/lib/eina/eina_promise.c
+++ b/src/lib/eina/eina_promise.c
@@ -103,6 +103,7 @@ struct _Eina_Promise {
103 Eina_Future *future; 103 Eina_Future *future;
104 Eina_Future_Scheduler *scheduler; 104 Eina_Future_Scheduler *scheduler;
105 Eina_Promise_Cancel_Cb cancel; 105 Eina_Promise_Cancel_Cb cancel;
106 Eina_Free_Cb free_cb;
106 const void *data; 107 const void *data;
107}; 108};
108 109
@@ -306,12 +307,19 @@ _eina_promise_link(Eina_Promise *p, Eina_Future *f)
306} 307}
307 308
308static void 309static void
310_eina_promise_free(Eina_Promise *p)
311{
312 if (p->free_cb) p->free_cb((void*) p->data);
313 eina_mempool_free(_promise_mp, p);
314}
315
316static void
309_eina_promise_cancel(Eina_Promise *p) 317_eina_promise_cancel(Eina_Promise *p)
310{ 318{
311 DBG("Cancelling promise: %p, data: %p, future: %p", p, p->data, p->future); 319 DBG("Cancelling promise: %p, data: %p, future: %p", p, p->data, p->future);
312 _eina_promise_unlink(p); 320 _eina_promise_unlink(p);
313 p->cancel((void *)p->data, p); 321 p->cancel((void *)p->data, p);
314 eina_mempool_free(_promise_mp, p); 322 _eina_promise_free(p);
315} 323}
316 324
317static void 325static void
@@ -516,7 +524,7 @@ _eina_promise_deliver(Eina_Promise *p,
516 DBG("Promise %p has no future", p); 524 DBG("Promise %p has no future", p);
517 eina_value_flush(&value); 525 eina_value_flush(&value);
518 } 526 }
519 eina_mempool_free(_promise_mp, p); 527 _eina_promise_free(p);
520} 528}
521 529
522Eina_Bool 530Eina_Bool
@@ -635,7 +643,7 @@ _eina_promise_clean_dispatch(Eina_Promise *p, Eina_Value v)
635 // This function is called on a promise created with a scheduler, not a continue one. 643 // This function is called on a promise created with a scheduler, not a continue one.
636 _eina_future_dispatch(p->scheduler, f, v); 644 _eina_future_dispatch(p->scheduler, f, v);
637 } 645 }
638 eina_mempool_free(_promise_mp, p); 646 _eina_promise_free(p);
639} 647}
640 648
641static Eina_Value 649static Eina_Value
@@ -1111,6 +1119,13 @@ eina_promise_data_set(Eina_Promise *p,
1111 p->data = data; 1119 p->data = data;
1112} 1120}
1113 1121
1122EAPI void
1123eina_promise_data_free_cb_set(Eina_Promise *p,
1124 Eina_Free_Cb free_cb)
1125{
1126 EINA_SAFETY_ON_NULL_RETURN(p);
1127 p->free_cb = free_cb;
1128}
1114 1129
1115static Eina_Value 1130static Eina_Value
1116_eina_future_cb_easy(void *data, const Eina_Value value, 1131_eina_future_cb_easy(void *data, const Eina_Value value,
diff --git a/src/lib/eina/eina_promise.h b/src/lib/eina/eina_promise.h
index 14e550d866..1896260dba 100644
--- a/src/lib/eina/eina_promise.h
+++ b/src/lib/eina/eina_promise.h
@@ -629,6 +629,14 @@ EAPI void *eina_promise_data_get(const Eina_Promise *p) EINA_ARG_NONNULL(1);
629EAPI void eina_promise_data_set(Eina_Promise *p, void *data) EINA_ARG_NONNULL(1); 629EAPI void eina_promise_data_set(Eina_Promise *p, void *data) EINA_ARG_NONNULL(1);
630 630
631/** 631/**
632 * Sets the free callback used when the data attached on the promise is freed just before the destruction of the promise itself.
633 *
634 * @param[in] p The promise to set the free callback on.
635 * @param[in] free_cb The free callback.
636 */
637EAPI void eina_promise_data_free_cb_set(Eina_Promise *p, Eina_Free_Cb free_cb);
638
639/**
632 * Resolves a promise. 640 * Resolves a promise.
633 * 641 *
634 * This function schedules a resolve event in a 642 * This function schedules a resolve event in a