Eina_Bool has_finished : 1;
Eina_Bool has_errored : 1;
+ Eina_Bool can_be_deleted : 1;
Eina_Bool is_cancelled : 1;
Eina_Bool is_manual_then : 1;
Eina_Bool is_first_then : 1;
_eina_promise_finish(_Eina_Promise_Default_Owner* promise)
{
promise->promise.has_finished = EINA_TRUE;
+ promise->promise.can_be_deleted = EINA_TRUE;
if (!promise->promise.is_manual_then)
{
_eina_promise_then_calls(promise);
static void
_eina_promise_unref(_Eina_Promise_Default* p)
{
- if (p->ref == 1 && p->has_finished)
+ if (p->ref <= 1 && p->has_finished && p->can_be_deleted)
{
_eina_promise_del(EINA_PROMISE_GET_OWNER(p));
}
p->promise.has_finished = p->promise.has_errored =
p->promise.is_cancelled = p->promise.is_manual_then = p->promise.is_pointer = EINA_FALSE;
+ p->promise.can_be_deleted = EINA_FALSE;
p->promise.is_first_then = EINA_TRUE;
p->promise.ref = 1;
memset(&p->promise.then_callbacks, 0, sizeof(p->promise.then_callbacks));
p->promise.has_finished = p->promise.has_errored =
p->promise.is_cancelled = p->promise.is_manual_then = EINA_FALSE;
p->promise.is_first_then = p->promise.is_pointer = EINA_TRUE;
+ p->promise.can_be_deleted = EINA_FALSE;
p->promise.ref = 1;
memset(&p->promise.then_callbacks, 0, sizeof(p->promise.then_callbacks));
memset(&p->promise.progress_callbacks, 0, sizeof(p->promise.progress_callbacks));
eina_lock_release(&v->lock);
}
-static void _cancel_callback(const void* data, Eina_Promise_Owner* promise EINA_UNUSED, Ecore_Thread* thread EINA_UNUSED)
+static void _cancel_callback(const void* data, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED)
{
_condition_var* v = (void*)data;
v->boolean = EINA_TRUE;
eina_condition_broadcast(&v->condvar);
eina_lock_release(&v->lock);
+
+ eina_promise_owner_value_set(promise, NULL, NULL);
}
static void _cancel_promise_callback(void* data EINA_UNUSED, Eina_Error value)
eina_promise_cancel(promise);
ck_assert(cancel_ran && ran);
+ ck_assert(eina_promise_owner_cancelled_is(owner));
+ ck_assert(!eina_promise_pending_is(promise));
+ ck_assert_int_eq(EINA_ERROR_PROMISE_CANCEL, eina_promise_error_get(promise));
+
+ // Finally free the owner
+ eina_promise_owner_value_set(owner, NULL, NULL);
+
+ ck_assert(ran);
eina_shutdown();
}
eina_promise_cancel(promise);
ck_assert(cancel_ran && ran);
+ ck_assert(eina_promise_owner_cancelled_is(owner));
+ ck_assert(!eina_promise_pending_is(promise));
+ ck_assert_int_eq(EINA_ERROR_PROMISE_CANCEL, eina_promise_error_get(promise));
+
+ // Free the owner
+ eina_promise_owner_value_set(owner, NULL, NULL);
+
+ ck_assert(ran);
eina_shutdown();
}