From 2167d851c38339d21f3a915beed778f232ff5d4b Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Thu, 14 Nov 2024 15:58:01 +0800 Subject: [PATCH 1/4] refactor: remove unused codes on closeable_t --- .../ten_runtime/common/closeable.h | 87 +--- core/src/ten_runtime/common/closeable.c | 379 +----------------- .../protocol/integrated/protocol_integrated.c | 1 - 3 files changed, 4 insertions(+), 463 deletions(-) diff --git a/core/include_internal/ten_runtime/common/closeable.h b/core/include_internal/ten_runtime/common/closeable.h index b5e8f792e..0ad00368f 100644 --- a/core/include_internal/ten_runtime/common/closeable.h +++ b/core/include_internal/ten_runtime/common/closeable.h @@ -317,17 +317,6 @@ typedef struct ten_closeable_t { // So we keep the offset rather than the raw pointer here. ptrdiff_t offset_in_impl; - /** - * @brief I want to customize the logic that determines whether I am the - * closing root, instead of using the default behavior of recursively - * searching through belong_to_resources. - * - * @note The second parameter of the callback (i.e., @a underlying_resource) - * will be NULL in this case. - */ - ten_closeable_is_closing_root_func_t is_closing_root_myself_cb; - void *is_closing_root_myself_data; - ten_list_t belong_to_resources; // ten_closeable_belong_to_info_t // This list is used to store those who are interested in my 'closed' events. @@ -346,7 +335,7 @@ typedef struct ten_closeable_t { } ten_closeable_t; TEN_RUNTIME_API bool ten_closeable_check_integrity(ten_closeable_t *self, - bool thread_check); + bool thread_check); /** * @example An implementation whose name is 'some_impl_t' and the name of the @@ -356,7 +345,8 @@ TEN_RUNTIME_API bool ten_closeable_check_integrity(ten_closeable_t *self, * ten_closeable_init(&impl->closeable, * offsetof(some_impl_t, closeable))) */ -TEN_RUNTIME_API void ten_closeable_init(ten_closeable_t *self, ptrdiff_t offset); +TEN_RUNTIME_API void ten_closeable_init(ten_closeable_t *self, + ptrdiff_t offset); TEN_RUNTIME_API void ten_closeable_deinit(ten_closeable_t *self); @@ -364,57 +354,6 @@ TEN_RUNTIME_API void ten_closeable_close(ten_closeable_t *self); TEN_RUNTIME_API bool ten_closeable_is_closed(ten_closeable_t *self); -TEN_RUNTIME_API bool ten_closeable_is_closing(ten_closeable_t *self); - -/** - * @brief Enable @a self to own a resource (@a underlying_resource). - * - * @param on_closed_all_done_cb Required. The owner (i.e., @a self) _must_ - * receive the 'on_closed_all_done' event of the underlying resource (i.e., - * @a underlying_resource) to destroy the underlying resource. - */ -TEN_RUNTIME_API void ten_closeable_add_underlying_resource( - ten_closeable_t *self, ten_closeable_t *underlying_resource, - ten_closeable_is_closing_root_func_t is_closing_root_cb, - void *is_closing_root_data, - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb, - void *on_intend_to_close_data, - ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb, - void *on_closed_all_done_data); - -/** - * @brief @a self depends on @a depend_resource, @a self will be an item of - * 'be_depended_on_resources' of @a depend_resource. - * - * @param on_closed_cb This is a function of @a depend_resource, which will be - * registered in @a self. This callback is used to notify @a depend_resource - * that someone depends on it has been closed. - * - * @param on_intend_to_close_cb This is a function of @a self, which will be - * registered in @a depend_resource. This callback is used to notify @a self - * when its dependency intends to close. - */ -TEN_RUNTIME_API void ten_closeable_add_depend_resource( - ten_closeable_t *self, ten_closeable_t *depend_resource, - ten_closeable_on_closed_func_t on_closed_cb, void *on_closed_data, - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb, - void *on_intend_to_close_data); - -/** - * @brief @a self depends on @a depend_resource. Use this function to release - * the dependency relationship from @a depend_resource only if needed, ex: @a - * self is closed. - */ -TEN_RUNTIME_API void ten_closeable_remove_depend_resource( - ten_closeable_t *self, ten_closeable_t *depend_resource); - -/** - * @brief @a self depends on @a depend_resource. Use this function to release - * the dependency relationship between @a self and @a depend_resource if needed. - */ -TEN_RUNTIME_API void ten_closeable_remove_depend_resource_bidirectional( - ten_closeable_t *self, ten_closeable_t *depend_resource); - /** * @note Add @a who_have_interest_on_me who is interested in my various closing * event to the closeable management of mine (i.e., @a self). @@ -425,25 +364,10 @@ TEN_RUNTIME_API void ten_closeable_remove_depend_resource_bidirectional( */ TEN_RUNTIME_API void ten_closeable_add_be_notified( ten_closeable_t *self, void *who_have_interest_on_me, - // intend_to_close event. - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb, - void *on_intend_to_close_data, - // closed event. - ten_closeable_on_closed_func_t on_closed_cb, void *on_closed_data, // closed_all_done event. ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb, void *on_closed_all_done_data); -/** - * @brief @a who_have_interest_on_me does not interest in the various closing - * events of @a self any more. Ex: @a self is closed. - */ -TEN_RUNTIME_API void ten_closeable_remove_be_notified( - ten_closeable_t *self, void *who_have_interest_on_me); - -TEN_RUNTIME_API void ten_closeable_intend_to_close(ten_closeable_t *self, - void *intend_to_close_data); - TEN_RUNTIME_API void ten_closeable_action_to_close_myself_done( ten_closeable_t *self, void *on_close_myself_data); @@ -451,8 +375,3 @@ TEN_RUNTIME_API void ten_closeable_set_action_to_close_myself( ten_closeable_t *self, ten_closeable_action_to_close_myself_func_t action_to_close_myself_cb, void *action_to_close_myself_data); - -TEN_RUNTIME_API void ten_closeable_set_is_closing_root_myself( - ten_closeable_t *self, - ten_closeable_is_closing_root_func_t is_closing_root_myself_cb, - void *is_closing_root_myself_data); diff --git a/core/src/ten_runtime/common/closeable.c b/core/src/ten_runtime/common/closeable.c index 79d2939d1..19ae99d33 100644 --- a/core/src/ten_runtime/common/closeable.c +++ b/core/src/ten_runtime/common/closeable.c @@ -6,13 +6,13 @@ // #include "include_internal/ten_runtime/common/closeable.h" -#include "ten_utils/macro/check.h" #include "ten_utils/container/list.h" #include "ten_utils/container/list_node.h" #include "ten_utils/container/list_node_ptr.h" #include "ten_utils/container/list_ptr.h" #include "ten_utils/lib/mutex.h" #include "ten_utils/lib/signature.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" #include "ten_utils/macro/memory.h" #include "ten_utils/sanitizer/thread_check.h" @@ -68,9 +68,6 @@ void ten_closeable_init(ten_closeable_t *self, ptrdiff_t offset) { self->state = TEN_CLOSEABLE_STATE_ALIVE; self->offset_in_impl = offset; - self->is_closing_root_myself_cb = NULL; - self->is_closing_root_myself_data = NULL; - ten_closeable_action_to_close_myself_init(&self->action_to_close_myself); ten_closeable_be_notified_resources_init(&self->be_notified_resources); @@ -126,18 +123,6 @@ void ten_closeable_set_action_to_close_myself( action_to_close_myself_data; } -void ten_closeable_set_is_closing_root_myself( - ten_closeable_t *self, - ten_closeable_is_closing_root_func_t is_closing_root_myself_cb, - void *is_closing_root_myself_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Access across threads."); - TEN_ASSERT(is_closing_root_myself_cb, "Invalid argument."); - - self->is_closing_root_myself_cb = is_closing_root_myself_cb; - self->is_closing_root_myself_data = is_closing_root_myself_data; -} - static void ten_closeable_on_closed_all_done(ten_closeable_t *self) { TEN_ASSERT(self, "Should not happen."); @@ -230,84 +215,6 @@ static void ten_closeable_on_closed_done_out_of_thread( } } -static void ten_closeable_make_intend_to_close_announcement( - ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - ten_list_foreach (&self->be_notified_resources.on_intend_to_close_queue, - iter) { - ten_closeable_on_intend_to_close_item_t *item = - ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item, "Should not happen."); - - if (item->on_intend_to_close_cb) { - item->on_intend_to_close_cb(self, item->who_have_interest_on_me, - item->on_intend_to_close_data); - } - } -} - -/** - * @return true if @a self is the closing root, otherwise false. - */ -static bool ten_closeable_is_closing_root_myself(ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - // If 'is_closing_root_myself_cb' is provided, it means the 'containing' - // instance has its own checking logic, rather than using the default behavior - // which search the closing roots through belong_to_resources. - if (self->is_closing_root_myself_cb) { - return self->is_closing_root_myself_cb(self, NULL, - self->is_closing_root_myself_data); - } - - // The following is the default behavior. - - bool I_am_root = true; - - ten_list_foreach (&self->belong_to_resources, iter) { - ten_closeable_belong_to_info_t *belong_to_info = - ten_ptr_listnode_get(iter.node); - TEN_ASSERT(belong_to_info, "Should not happen."); - TEN_ASSERT(ten_closeable_check_integrity(belong_to_info->belong_to, true) && - belong_to_info->is_closing_root_cb, - "Should not happen."); - - if (belong_to_info->is_closing_root_cb( - belong_to_info->belong_to, self, - belong_to_info->is_closing_root_data) == true) { - // Find a new root, so I am not the root. - I_am_root = false; - - break; - } - } - - return I_am_root; -} - -void ten_closeable_intend_to_close(ten_closeable_t *self, - TEN_UNUSED void *intend_to_close_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - if (self->state >= TEN_CLOSEABLE_STATE_CLOSING) { - return; - } - - // Make an announcement first. - ten_closeable_make_intend_to_close_announcement(self); - - // Determine if I am the closing root. - bool I_am_root = ten_closeable_is_closing_root_myself(self); - if (I_am_root) { - // I am the closing root, so trigger the closing directly. - ten_closeable_close(self); - } -} - static bool ten_closeable_could_start_to_close_myself(ten_closeable_t *self) { TEN_ASSERT(self && ten_closeable_check_integrity(self, true), "Invalid argument."); @@ -393,46 +300,6 @@ static void ten_closeable_do_close(ten_closeable_t *self) { } } -static void ten_closeable_on_underlying_resource_closed_default( - ten_closeable_t *underlying_resource, void *self_, void *on_closed_data, - ten_closeable_on_closed_done_func_t on_closed_done) { - TEN_ASSERT(underlying_resource && - ten_closeable_check_integrity(underlying_resource, true), - "Invalid argument."); - - ten_closeable_t *self = (ten_closeable_t *)self_; - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - ten_list_remove_ptr(&self->underlying_resources, underlying_resource); - - if (self->state == TEN_CLOSEABLE_STATE_CLOSING) { - if (ten_closeable_could_start_to_close_myself(self)) { - ten_closeable_do_close(self); - } - } - - // Notify my underlying resource that I have received its 'closed' event and - // have completed all the tasks I needed to do. - if (on_closed_done) { - on_closed_done(underlying_resource, self, on_closed_data); - } -} - -static void ten_closeable_on_intend_to_close_item_destroy( - ten_closeable_on_intend_to_close_item_t *self) { - TEN_ASSERT(self, "Invalid argument."); - - TEN_FREE(self); -} - -static void ten_closeable_on_closed_item_destroy( - ten_closeable_on_closed_item_t *self) { - TEN_ASSERT(self, "Invalid argument."); - - TEN_FREE(self); -} - static void ten_closeable_on_closed_all_done_item_destroy( ten_closeable_on_closed_all_done_item_t *self) { TEN_ASSERT(self, "Invalid argument."); @@ -442,45 +309,11 @@ static void ten_closeable_on_closed_all_done_item_destroy( void ten_closeable_add_be_notified( ten_closeable_t *self, void *who_have_interest_on_me, - // intend_to_close event. - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb, - void *on_intend_to_close_data, - // on_closed event. - ten_closeable_on_closed_func_t on_closed_cb, void *on_closed_data, ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb, void *on_closed_all_done_data) { TEN_ASSERT(self && ten_closeable_check_integrity(self, true), "Invalid argument."); - if (on_intend_to_close_cb) { - ten_closeable_on_intend_to_close_item_t *item = - TEN_MALLOC(sizeof(ten_closeable_on_intend_to_close_item_t)); - TEN_ASSERT(item, "Failed to allocate memory."); - - item->who_have_interest_on_me = who_have_interest_on_me; - item->on_intend_to_close_cb = on_intend_to_close_cb; - item->on_intend_to_close_data = on_intend_to_close_data; - - ten_list_push_ptr_back( - &self->be_notified_resources.on_intend_to_close_queue, item, - (ten_ptr_listnode_destroy_func_t) - ten_closeable_on_intend_to_close_item_destroy); - } - - if (on_closed_cb) { - ten_closeable_on_closed_item_t *item = - TEN_MALLOC(sizeof(ten_closeable_on_closed_item_t)); - TEN_ASSERT(item, "Failed to allocate memory."); - - item->who_have_interest_on_me = who_have_interest_on_me; - item->on_closed_cb = on_closed_cb; - item->on_closed_data = on_closed_data; - - ten_list_push_ptr_back( - &self->be_notified_resources.on_closed_queue, item, - (ten_ptr_listnode_destroy_func_t)ten_closeable_on_closed_item_destroy); - } - if (on_closed_all_done_cb) { ten_closeable_on_closed_all_done_item_t *item = TEN_MALLOC(sizeof(ten_closeable_on_closed_all_done_item_t)); @@ -497,209 +330,6 @@ void ten_closeable_add_be_notified( } } -static void ten_closeable_on_depended_resource_closed_default( - ten_closeable_t *self, void *depend, void *on_closed_data, - ten_closeable_on_closed_done_func_t on_closed_done) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Access across threads."); - - ten_closeable_t *depend_ = (ten_closeable_t *)depend; - TEN_ASSERT(depend_ && ten_closeable_check_integrity(depend_, true), - "Access across threads."); - - // Remove @a self from the 'be_depended_on_resources' queue of @a depend_. - ten_closeable_remove_depend_resource(self, depend_); - - // Note that @a self might be destroyed by its owner after the call to @a - // on_closed_done. - if (on_closed_done) { - on_closed_done(self, depend, on_closed_data); - } -} - -void ten_closeable_add_depend_resource( - ten_closeable_t *self, ten_closeable_t *depend, - ten_closeable_on_closed_func_t on_closed_cb, void *on_closed_data, - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb, - void *on_intend_to_close_data) { - ten_list_push_ptr_back(&depend->be_depended_on_resources, self, NULL); - - // I will receive the 'intend_to_close' event of the depend resource. I maybe - // not able to keep running if my dependency is closed. This is an opportunity - // for the closing tree, I belong to, to start the closing process. - if (on_intend_to_close_cb) { - ten_closeable_add_be_notified(depend, self, on_intend_to_close_cb, - on_intend_to_close_data, NULL, NULL, NULL, - NULL); - } else { - // I and my dependency are in the different closing trees, which means we - // will be closed by our owners. So if someone depends on me, but he does - // not want to care about my 'on_intend_to_close' event, we should not add a - // default behavior such as 'intend_to_close' him when I am closing. - } - - // My dependency should receive my 'on_closed' event, then my dependency could - // be able to close itself if it is being closed. - // - // We have to add a default behavior to do some cleaning if the 'on_closed_cb' - // is NULL. - ten_closeable_add_be_notified( - self, depend, NULL, NULL, - on_closed_cb ? on_closed_cb - : ten_closeable_on_depended_resource_closed_default, - on_closed_data, NULL, NULL); -} - -void ten_closeable_remove_be_notified(ten_closeable_t *self, - void *who_have_interest_on_me) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Access across threads."); - - ten_list_foreach (&self->be_notified_resources.on_closed_all_done_queue, - iter) { - ten_closeable_on_closed_all_done_item_t *item = - ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item, "Should not happen."); - - if (item->who_have_interest_on_me == who_have_interest_on_me) { - ten_list_remove_node( - &self->be_notified_resources.on_closed_all_done_queue, iter.node); - } - } - - ten_list_foreach (&self->be_notified_resources.on_closed_queue, iter) { - ten_closeable_on_closed_item_t *item = ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item, "Should not happen."); - - if (item->who_have_interest_on_me == who_have_interest_on_me) { - ten_list_remove_node(&self->be_notified_resources.on_closed_queue, - iter.node); - } - } - - ten_list_foreach (&self->be_notified_resources.on_intend_to_close_queue, - iter) { - ten_closeable_on_intend_to_close_item_t *item = - ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item, "Should not happen."); - - if (item->who_have_interest_on_me == who_have_interest_on_me) { - ten_list_remove_node( - &self->be_notified_resources.on_intend_to_close_queue, iter.node); - } - } -} - -void ten_closeable_remove_depend_resource(ten_closeable_t *self, - ten_closeable_t *depend_resource) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Access across threads."); - TEN_ASSERT( - depend_resource && ten_closeable_check_integrity(depend_resource, true), - "Access across threads."); - - // Delete 'self' from 'be_depended_on_resources' of 'depend_resource'. - ten_list_remove_ptr(&depend_resource->be_depended_on_resources, self); - - // Remove all the events that @a depend_resource subscribes on @a self. - ten_closeable_remove_be_notified(depend_resource, self); - - if (depend_resource->state == TEN_CLOSEABLE_STATE_CLOSING) { - if (ten_closeable_could_start_to_close_myself(depend_resource)) { - ten_closeable_do_close(depend_resource); - } - } -} - -void ten_closeable_remove_depend_resource_bidirectional( - ten_closeable_t *self, ten_closeable_t *depend_resource) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Access across threads."); - TEN_ASSERT( - depend_resource && ten_closeable_check_integrity(depend_resource, true), - "Access across threads."); - - ten_closeable_remove_be_notified(self, depend_resource); - ten_closeable_remove_depend_resource(self, depend_resource); -} - -static void ten_closeable_belong_to_info_destroy( - ten_closeable_belong_to_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); - - TEN_FREE(info); -} - -static bool ten_closeable_is_closing_root_default( - ten_closeable_t *self, TEN_UNUSED ten_closeable_t *underlying_resource, - TEN_UNUSED void *is_closing_root_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - TEN_ASSERT(underlying_resource && - ten_closeable_check_integrity(underlying_resource, true), - "Invalid argument."); - - // The default behavior is whether 'self' is a root is determined by whether - // it has an owner. - return ten_list_is_empty(&self->belong_to_resources); -} - -static void ten_closeable_add_belong_to_resource( - ten_closeable_t *self, ten_closeable_t *belong_to, - ten_closeable_is_closing_root_func_t is_closing_root_cb, - void *is_closing_root_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - TEN_ASSERT(belong_to && ten_closeable_check_integrity(belong_to, true), - "Invalid argument."); - - ten_closeable_belong_to_info_t *info = - (ten_closeable_belong_to_info_t *)TEN_MALLOC( - sizeof(ten_closeable_belong_to_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); - - info->belong_to = belong_to; - - info->is_closing_root_cb = is_closing_root_cb - ? is_closing_root_cb - : ten_closeable_is_closing_root_default; - info->is_closing_root_data = is_closing_root_data; - - ten_list_push_ptr_back( - &self->belong_to_resources, info, - (ten_ptr_listnode_destroy_func_t)ten_closeable_belong_to_info_destroy); -} - -void ten_closeable_add_underlying_resource( - ten_closeable_t *self, ten_closeable_t *underlying_resource, - ten_closeable_is_closing_root_func_t is_closing_root_cb, - void *is_closing_root_data, - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb, - void *on_intend_to_close_data, - ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb, - void *on_closed_all_done_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Access across threads."); - TEN_ASSERT(underlying_resource && - ten_closeable_check_integrity(underlying_resource, true), - "Access across threads."); - TEN_ASSERT(on_closed_all_done_cb, - "The owner must subscribe the 'on_close_all_done' events of its " - "underlying resources."); - - ten_list_push_ptr_back(&self->underlying_resources, underlying_resource, - NULL); - - // I should receive the closed event from 'resource'. - ten_closeable_add_be_notified( - underlying_resource, self, on_intend_to_close_cb, on_intend_to_close_data, - ten_closeable_on_underlying_resource_closed_default, NULL, - on_closed_all_done_cb, on_closed_all_done_data); - - ten_closeable_add_belong_to_resource( - underlying_resource, self, is_closing_root_cb, is_closing_root_data); -} - void ten_closeable_close(ten_closeable_t *self) { TEN_ASSERT(self && ten_closeable_check_integrity(self, true), "Invalid argument."); @@ -725,10 +355,3 @@ bool ten_closeable_is_closed(ten_closeable_t *self) { return self->state == TEN_CLOSEABLE_STATE_CLOSED; } - -bool ten_closeable_is_closing(ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - return self->state == TEN_CLOSEABLE_STATE_CLOSING; -} diff --git a/core/src/ten_runtime/protocol/integrated/protocol_integrated.c b/core/src/ten_runtime/protocol/integrated/protocol_integrated.c index c949fd70e..b45a25dad 100644 --- a/core/src/ten_runtime/protocol/integrated/protocol_integrated.c +++ b/core/src/ten_runtime/protocol/integrated/protocol_integrated.c @@ -674,7 +674,6 @@ void ten_protocol_integrated_init( &self->base.closeable, ten_protocol_action_to_close_myself, NULL); ten_closeable_add_be_notified(&self->base.closeable, &self->base.closeable, - NULL, NULL, NULL, NULL, ten_protocol_on_impl_closed_all_done, NULL); self->base.role = TEN_PROTOCOL_ROLE_INVALID; From 587d8b4c7800b69b39900f6a39902442fe0bab47 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Thu, 14 Nov 2024 16:20:41 +0800 Subject: [PATCH 2/4] refactor: remove unused codes on closeable_t --- .../ten_runtime/common/closeable.h | 22 --------- core/src/ten_runtime/common/closeable.c | 46 +------------------ 2 files changed, 1 insertion(+), 67 deletions(-) diff --git a/core/include_internal/ten_runtime/common/closeable.h b/core/include_internal/ten_runtime/common/closeable.h index 0ad00368f..2e4ce034b 100644 --- a/core/include_internal/ten_runtime/common/closeable.h +++ b/core/include_internal/ten_runtime/common/closeable.h @@ -206,17 +206,6 @@ typedef bool (*ten_closeable_is_closing_root_func_t)( ten_closeable_t *self, ten_closeable_t *underlying_resource, void *is_closing_root_data); -/** - * @brief This structure is used to represent which ten_closeable_t instance - * (i.e., @a belong_to) owns a given ten_closeable_t instance. - */ -typedef struct ten_closeable_belong_to_info_t { - ten_closeable_t *belong_to; - - ten_closeable_is_closing_root_func_t is_closing_root_cb; - void *is_closing_root_data; -} ten_closeable_belong_to_info_t; - /** * @brief This function is used to indicate that the action of closing the * ten_closeable_t itself has been completed entirely. @@ -317,20 +306,9 @@ typedef struct ten_closeable_t { // So we keep the offset rather than the raw pointer here. ptrdiff_t offset_in_impl; - ten_list_t belong_to_resources; // ten_closeable_belong_to_info_t - // This list is used to store those who are interested in my 'closed' events. ten_closeable_be_notified_resources_t be_notified_resources; - ten_list_t underlying_resources; // ten_closeable_t - - // The resources depend on me. - // - // If A depends on B, it means B could only be closed after A is closed. So A - // will be kept in the 'be_depended_on_resources' list of B, then B could know - // whether all resources depend on it are closed. - ten_list_t be_depended_on_resources; // ten_closeable_t - ten_closeable_action_to_close_myself_t action_to_close_myself; } ten_closeable_t; diff --git a/core/src/ten_runtime/common/closeable.c b/core/src/ten_runtime/common/closeable.c index 19ae99d33..d677f0e35 100644 --- a/core/src/ten_runtime/common/closeable.c +++ b/core/src/ten_runtime/common/closeable.c @@ -71,10 +71,6 @@ void ten_closeable_init(ten_closeable_t *self, ptrdiff_t offset) { ten_closeable_action_to_close_myself_init(&self->action_to_close_myself); ten_closeable_be_notified_resources_init(&self->be_notified_resources); - - ten_list_init(&self->belong_to_resources); - ten_list_init(&self->be_depended_on_resources); - ten_list_init(&self->underlying_resources); } static void ten_closeable_be_notified_resources_deinit( @@ -104,10 +100,6 @@ void ten_closeable_deinit(ten_closeable_t *self) { self->state = TEN_CLOSEABLE_STATE_ALIVE; ten_closeable_be_notified_resources_deinit(&self->be_notified_resources); - - ten_list_clear(&self->belong_to_resources); - ten_list_clear(&self->be_depended_on_resources); - ten_list_clear(&self->underlying_resources); } void ten_closeable_set_action_to_close_myself( @@ -215,35 +207,6 @@ static void ten_closeable_on_closed_done_out_of_thread( } } -static bool ten_closeable_could_start_to_close_myself(ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - // Check if all remaining underlying_resources have been closed. - ten_list_foreach (&self->underlying_resources, iter) { - ten_closeable_t *target = ten_ptr_listnode_get(iter.node); - TEN_ASSERT(target && ten_closeable_check_integrity(target, true), - "Should not happen."); - - if (!ten_closeable_is_closed(target)) { - return false; - } - } - - // Check if all remaining depend_resources have been closed. - ten_list_foreach (&self->be_depended_on_resources, iter) { - ten_closeable_t *target = ten_ptr_listnode_get(iter.node); - TEN_ASSERT(target && ten_closeable_check_integrity(target, true), - "Should not happen."); - - if (!ten_closeable_is_closed(target)) { - return false; - } - } - - return true; -} - void ten_closeable_action_to_close_myself_done( ten_closeable_t *self, TEN_UNUSED void *on_close_myself_data) { TEN_ASSERT(self && ten_closeable_check_integrity(self, true), @@ -339,14 +302,7 @@ void ten_closeable_close(ten_closeable_t *self) { self->state = TEN_CLOSEABLE_STATE_CLOSING; - if (ten_closeable_could_start_to_close_myself(self)) { - ten_closeable_do_close(self); - } else { - ten_list_foreach (&self->underlying_resources, iter) { - ten_closeable_t *resource = ten_ptr_listnode_get(iter.node); - ten_closeable_close(resource); - } - } + ten_closeable_do_close(self); } bool ten_closeable_is_closed(ten_closeable_t *self) { From fd45841e32e33f0064381179d3f6a88512f963dc Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Thu, 14 Nov 2024 17:10:55 +0800 Subject: [PATCH 3/4] refactor: remove unused codes on closeable_t --- .../ten_runtime/common/closeable.h | 185 ----------------- .../ten_runtime/protocol/close.h | 4 - .../ten_runtime/protocol/protocol.h | 1 + core/src/ten_runtime/common/closeable.c | 193 +----------------- core/src/ten_runtime/protocol/close.c | 39 +--- .../protocol/integrated/protocol_integrated.c | 5 - 6 files changed, 6 insertions(+), 421 deletions(-) diff --git a/core/include_internal/ten_runtime/common/closeable.h b/core/include_internal/ten_runtime/common/closeable.h index 2e4ce034b..c415f7f6a 100644 --- a/core/include_internal/ten_runtime/common/closeable.h +++ b/core/include_internal/ten_runtime/common/closeable.h @@ -9,110 +9,13 @@ #include "ten_runtime/ten_config.h" #include "ten_utils/container/list.h" -#include "ten_utils/lib/mutex.h" #include "ten_utils/lib/signature.h" #include "ten_utils/sanitizer/thread_check.h" #define TEN_CLOSEABLE_SIGNATURE 0x7263656c6f736564U -typedef enum TEN_CLOSEABLE_STATE { - TEN_CLOSEABLE_STATE_ALIVE, - TEN_CLOSEABLE_STATE_CLOSING, - TEN_CLOSEABLE_STATE_CLOSED, -} TEN_CLOSEABLE_STATE; - -/** - * @brief The enum is used to represent whether the 'on_closed_done()' callback - * of ten_closeable_t will be invoked in the thread where ten_closeable_t - * resides. - * - * Suppose that there are a 'ten_closeable_t' instance (we named it 'CA'), and - * another instance (we named it 'CB') are interested in the 'closed' event of - * CA. After CA is closed, CB will receive the 'on_closed' event of CA, and then - * CA should receive the 'on_closed_done' acked from CB. As CA and CB might - * belongs to different threads, the 'on_closed_done' event maybe delivered to - * CA from other threads, and normally, we prefer to use the runloop tasks to - * ensure the thread safety in this case. However, the runloop of CA might be - * already closed before the 'on_closed_done' event being delivered to CA. - * - * The logic of closing is determined by the implementation of the runloop, we - * cannot make any restrictions. In other words, the runloop might or might not - * be able to deliver events after it is closed. - * - * Usually, the existence of the runloop of CA is in the following two forms. - * - * - CA owns a runloop. - * - * In this case, the runloop will be closed before the CA is closed, as the - * runloop is a resource owned by CA. - * - * - CA does not have its own runloop. In this case, CA uses the runloop belongs - * to another 'ten_closeable_t' instance (we named it 'CC'). In the semantics - * of ten_closeable_t, CA depends on CC. - * - * In this case, CC might start to close itself after it receives the - * 'on_closed' event of CA. So the runloop could not be used to deliver the - * 'on_closed_done' event as it might be already closed. - * - * Thus, the 'on_closed_done' could be received in the following two conditions. - * - * - In the thread of CA. - * - * * Because CA and CB (who is interested in the 'closed' event of CA) are in - * the same thread. - * - * * Or because the runloop of CA (including the runloop CA depends on) is - * still able to deliver events when it is closed, so CB could deliver the - * 'on_closed_done()' ack to CA through the runloop of CA. - * - * - Out of the thread of CA. - * - * * CA and CB are in the different threads, and the runloop of CA could not - * be able to deliver events when it is closed. Therefore, the - * 'on_closed_done()' of CA would be called in the thread of CB. - * - * In the meanwhile, I can not use the runloop of my owner to deliver the - * 'on_closed_done' event of mine, because not all the 'ten_closeable_t' - * instances always have an owner. - */ -typedef enum TEN_CLOSEABLE_ON_CLOSED_DONE_MODE { - // The 'on_closed_done()' of mine is called in my own thread, it means that - // the accesses to me is thread safe. - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_IN_OWN_THREAD, - - // The 'on_closed_done()' of mine is called in other threads. One possible use - // case of this mode is that others can not use the runloop I am currently in - // to the 'on_closed_done' event to me as the runloop can not be used when I - // am closed. In this case, we have to ensure the thread safety in help of - // some mutex locks. - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_OUT_OWN_THREAD, -} TEN_CLOSEABLE_ON_CLOSED_DONE_MODE; - typedef struct ten_closeable_t ten_closeable_t; -/** - * @brief This function is used to indicate that the closed event of @a self has - * been processed by @a who_have_interest_on_me. - */ -typedef void (*ten_closeable_on_closed_done_func_t)( - ten_closeable_t *self, void *who_have_interest_on_me, void *on_closed_data); - -/** - * @brief This function is used to notify others (i.e., @a - * who_have_interest_on_me) who are interested in the 'closed' event of mine. - * - * @param self The instance who implements the 'ten_closeable_t' interface. - * @param who_have_interest_on_me The instance who is interested in the 'closed' - * event of mine. - * @param on_closed_data The data bound to the 'on_closed' callback. - * @param on_closed_done The callback to notify the 'closed' event is handled by - * @a other completely. This callback must not be NULL, and @a other must call - * this callback when it handles the 'closed' event completely. - */ -typedef void (*ten_closeable_on_closed_func_t)( - ten_closeable_t *self, void *who_have_interest_on_me, void *on_closed_data, - ten_closeable_on_closed_done_func_t on_closed_done); - /** * @brief This function is used to notify others (i.e., @a * who_have_interest_on_me) who are interested in the 'on_closed_all_done' event @@ -132,26 +35,6 @@ typedef void (*ten_closeable_on_closed_all_done_func_t)( ten_closeable_t *self, void *who_have_interest_on_me, void *on_closed_all_done_data); -/** - * @brief This function is used to notify others (@a who_have_interest_on_me) - * who are interested in my intend_to_close event. - */ -typedef void (*ten_closeable_on_intend_to_close_func_t)( - ten_closeable_t *self, void *who_have_interest_on_me, - void *on_intend_to_close_data); - -typedef struct ten_closeable_on_intend_to_close_item_t { - void *who_have_interest_on_me; - ten_closeable_on_intend_to_close_func_t on_intend_to_close_cb; - void *on_intend_to_close_data; -} ten_closeable_on_intend_to_close_item_t; - -typedef struct ten_closeable_on_closed_item_t { - void *who_have_interest_on_me; - ten_closeable_on_closed_func_t on_closed_cb; - void *on_closed_data; -} ten_closeable_on_closed_item_t; - typedef struct ten_closeable_on_closed_all_done_item_t { void *who_have_interest_on_me; ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb; @@ -167,66 +50,11 @@ typedef struct ten_closeable_on_closed_all_done_item_t { * prefer to use three different queues here. */ typedef struct ten_closeable_be_notified_resources_t { - // Is interested in 'intend_to_close' event. The type of the element is - // 'ten_closeable_on_intend_to_close_item_t'. - ten_list_t on_intend_to_close_queue; - - // @{ - // Is interested in 'closed' event. The type of the element is - // 'ten_closeable_on_closed_item_t'. - ten_list_t on_closed_queue; - - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE on_closed_done_mode; - ten_closeable_on_closed_done_func_t on_closed_done_cb; - - // The expected count of 'on_closed_done' event I will receive from others, if - // the 'on_closed_done_mode' is 'OUT_OWN_THREAD'. As the 'on_closed_done' - // event is called in other threads, it's unsafe to access the fields such - // as 'on_closed_queue' and 'on_closed_all_done_queue' of this structure. So - // we have to use the mutex lock to ensure the safety. - ten_mutex_t *on_closed_done_mutex; - - // The expected count of 'on_closed_done' event I will receive from others, - // it's the size of the 'on_closed_queue'. It's just a faster way to determine - // whether I have received all 'on_closed_done' events from others, rather - // than locking all the 'on_closed_queue'. - size_t expected_on_closed_done_count; - // @} - // Is interested in 'closed_all_done' event. The type of the element is // 'ten_closeable_on_closed_all_done_item_t'. ten_list_t on_closed_all_done_queue; } ten_closeable_be_notified_resources_t; -/** - * @brief This function is used to determine whether @a self is the higher-level - * root when @a underlying_resource wants to close. - */ -typedef bool (*ten_closeable_is_closing_root_func_t)( - ten_closeable_t *self, ten_closeable_t *underlying_resource, - void *is_closing_root_data); - -/** - * @brief This function is used to indicate that the action of closing the - * ten_closeable_t itself has been completed entirely. - */ -typedef void (*ten_closeable_action_to_close_myself_done_func_t)( - ten_closeable_t *self, void *action_to_close_myself_data); - -/** - * @brief This function is used to represent a customized action for a - * 'ten_closeable_t' to close itself. - */ -typedef void (*ten_closeable_action_to_close_myself_func_t)( - ten_closeable_t *self, void *action_to_close_myself_data, - ten_closeable_action_to_close_myself_done_func_t - action_to_close_myself_done); - -typedef struct ten_closeable_action_to_close_myself_t { - ten_closeable_action_to_close_myself_func_t action_to_close_myself_cb; - void *action_to_close_myself_data; -} ten_closeable_action_to_close_myself_t; - /** * @brief The standard interface for closing a resource. * @@ -268,8 +96,6 @@ typedef struct ten_closeable_t { // All operations _must_ be called in the same thread. ten_sanitizer_thread_check_t thread_check; - TEN_CLOSEABLE_STATE state; - // The offset of this 'ten_closeable_t' object in the implementation who // implements the 'ten_closeable_t' interface. It will be used to get the raw // pointer of the implementation. @@ -308,8 +134,6 @@ typedef struct ten_closeable_t { // This list is used to store those who are interested in my 'closed' events. ten_closeable_be_notified_resources_t be_notified_resources; - - ten_closeable_action_to_close_myself_t action_to_close_myself; } ten_closeable_t; TEN_RUNTIME_API bool ten_closeable_check_integrity(ten_closeable_t *self, @@ -328,10 +152,6 @@ TEN_RUNTIME_API void ten_closeable_init(ten_closeable_t *self, TEN_RUNTIME_API void ten_closeable_deinit(ten_closeable_t *self); -TEN_RUNTIME_API void ten_closeable_close(ten_closeable_t *self); - -TEN_RUNTIME_API bool ten_closeable_is_closed(ten_closeable_t *self); - /** * @note Add @a who_have_interest_on_me who is interested in my various closing * event to the closeable management of mine (i.e., @a self). @@ -348,8 +168,3 @@ TEN_RUNTIME_API void ten_closeable_add_be_notified( TEN_RUNTIME_API void ten_closeable_action_to_close_myself_done( ten_closeable_t *self, void *on_close_myself_data); - -TEN_RUNTIME_API void ten_closeable_set_action_to_close_myself( - ten_closeable_t *self, - ten_closeable_action_to_close_myself_func_t action_to_close_myself_cb, - void *action_to_close_myself_data); diff --git a/core/include_internal/ten_runtime/protocol/close.h b/core/include_internal/ten_runtime/protocol/close.h index 0f96a1aaf..86b44fb07 100644 --- a/core/include_internal/ten_runtime/protocol/close.h +++ b/core/include_internal/ten_runtime/protocol/close.h @@ -27,10 +27,6 @@ TEN_RUNTIME_PRIVATE_API void ten_protocol_set_on_closed( TEN_RUNTIME_PRIVATE_API void ten_protocol_on_close(ten_protocol_t *self); -TEN_RUNTIME_API void ten_protocol_action_to_close_myself( - ten_closeable_t *self_, void *close_myself_data, - ten_closeable_action_to_close_myself_done_func_t close_myself_done); - TEN_RUNTIME_API void ten_protocol_on_impl_intends_to_close( ten_closeable_t *impl, void *self_closeable, void *on_intend_to_close_data); diff --git a/core/include_internal/ten_runtime/protocol/protocol.h b/core/include_internal/ten_runtime/protocol/protocol.h index d0bc388b7..7374e0f06 100644 --- a/core/include_internal/ten_runtime/protocol/protocol.h +++ b/core/include_internal/ten_runtime/protocol/protocol.h @@ -12,6 +12,7 @@ #include "include_internal/ten_runtime/protocol/close.h" #include "ten_runtime/protocol/protocol.h" #include "ten_utils/container/list.h" +#include "ten_utils/lib/mutex.h" #include "ten_utils/lib/ref.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/lib/string.h" diff --git a/core/src/ten_runtime/common/closeable.c b/core/src/ten_runtime/common/closeable.c index d677f0e35..7cc476fd5 100644 --- a/core/src/ten_runtime/common/closeable.c +++ b/core/src/ten_runtime/common/closeable.c @@ -10,7 +10,6 @@ #include "ten_utils/container/list_node.h" #include "ten_utils/container/list_node_ptr.h" #include "ten_utils/container/list_ptr.h" -#include "ten_utils/lib/mutex.h" #include "ten_utils/lib/signature.h" #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" @@ -31,31 +30,10 @@ bool ten_closeable_check_integrity(ten_closeable_t *self, bool thread_check) { return true; } -static void ten_closeable_action_to_close_myself_init( - ten_closeable_action_to_close_myself_t *self) { - TEN_ASSERT(self, "Invalid argument."); - - self->action_to_close_myself_cb = NULL; - self->action_to_close_myself_data = NULL; -} - static void ten_closeable_be_notified_resources_init( ten_closeable_be_notified_resources_t *self) { TEN_ASSERT(self, "Invalid argument."); - self->on_closed_done_mode = TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_IN_OWN_THREAD; - self->on_closed_done_cb = NULL; - - self->expected_on_closed_done_count = 0; - self->on_closed_done_mutex = NULL; - - if (self->on_closed_done_mode == - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_OUT_OWN_THREAD) { - self->on_closed_done_mutex = ten_mutex_create(); - } - - ten_list_init(&self->on_intend_to_close_queue); - ten_list_init(&self->on_closed_queue); ten_list_init(&self->on_closed_all_done_queue); } @@ -65,11 +43,8 @@ void ten_closeable_init(ten_closeable_t *self, ptrdiff_t offset) { ten_signature_set(&self->signature, (ten_signature_t)TEN_CLOSEABLE_SIGNATURE); ten_sanitizer_thread_check_init_with_current_thread(&self->thread_check); - self->state = TEN_CLOSEABLE_STATE_ALIVE; self->offset_in_impl = offset; - ten_closeable_action_to_close_myself_init(&self->action_to_close_myself); - ten_closeable_be_notified_resources_init(&self->be_notified_resources); } @@ -77,14 +52,7 @@ static void ten_closeable_be_notified_resources_deinit( ten_closeable_be_notified_resources_t *self) { TEN_ASSERT(self, "Invalid argument."); - ten_list_clear(&self->on_intend_to_close_queue); - ten_list_clear(&self->on_closed_queue); ten_list_clear(&self->on_closed_all_done_queue); - - if (self->on_closed_done_mutex) { - ten_mutex_destroy(self->on_closed_done_mutex); - self->on_closed_done_mutex = NULL; - } } void ten_closeable_deinit(ten_closeable_t *self) { @@ -97,49 +65,17 @@ void ten_closeable_deinit(ten_closeable_t *self) { ten_signature_set(&self->signature, 0); ten_sanitizer_thread_check_deinit(&self->thread_check); - self->state = TEN_CLOSEABLE_STATE_ALIVE; - ten_closeable_be_notified_resources_deinit(&self->be_notified_resources); } -void ten_closeable_set_action_to_close_myself( - ten_closeable_t *self, - ten_closeable_action_to_close_myself_func_t action_to_close_myself_cb, - void *action_to_close_myself_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - self->action_to_close_myself.action_to_close_myself_cb = - action_to_close_myself_cb; - self->action_to_close_myself.action_to_close_myself_data = - action_to_close_myself_data; -} - static void ten_closeable_on_closed_all_done(ten_closeable_t *self) { TEN_ASSERT(self, "Should not happen."); - - bool is_thread_safe = self->be_notified_resources.on_closed_done_mode == - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_IN_OWN_THREAD; - TEN_ASSERT(ten_closeable_check_integrity(self, is_thread_safe), - "Invalid argument."); + TEN_ASSERT(ten_closeable_check_integrity(self, true), "Invalid argument."); ten_list_t on_closed_all_done_queue = TEN_LIST_INIT_VAL; - // Because on_closed_done() may be invoked in different threads than the one - // where ten_closeable_t resides, it is necessary to determine whether to - // perform lock/unlock operations based on thread safety principles. - if (is_thread_safe) { - ten_list_swap(&on_closed_all_done_queue, - &self->be_notified_resources.on_closed_all_done_queue); - } else { - TEN_ASSERT(self->be_notified_resources.on_closed_done_mutex, - "Should not happen."); - - TEN_DO_WITH_MUTEX_LOCK(self->be_notified_resources.on_closed_done_mutex, { - ten_list_swap(&on_closed_all_done_queue, - &self->be_notified_resources.on_closed_all_done_queue); - }); - } + ten_list_swap(&on_closed_all_done_queue, + &self->be_notified_resources.on_closed_all_done_queue); ten_list_foreach (&on_closed_all_done_queue, iter) { ten_closeable_on_closed_all_done_item_t *item = @@ -153,114 +89,12 @@ static void ten_closeable_on_closed_all_done(ten_closeable_t *self) { ten_list_clear(&on_closed_all_done_queue); } -static void ten_closeable_on_closed_done(ten_closeable_t *self, - void *who_have_interest_on_me, - void *on_closed_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - ten_list_t *on_closed_queue = &self->be_notified_resources.on_closed_queue; - - bool found = false; - ten_list_foreach (on_closed_queue, iter) { - ten_closeable_on_closed_item_t *item = ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item && item->on_closed_cb, "Should not happen."); - - if (item->who_have_interest_on_me == who_have_interest_on_me && - item->on_closed_data == on_closed_data) { - found = true; - ten_list_remove_node(on_closed_queue, iter.node); - - break; - } - } - - TEN_ASSERT(found, "Should not happen."); - - if (ten_list_is_empty(on_closed_queue)) { - // All other resources who are interested in my 'closed' event handle the - // 'closed' event completely. - ten_closeable_on_closed_all_done(self); - } -} - -static void ten_closeable_on_closed_done_out_of_thread( - ten_closeable_t *self, TEN_UNUSED void *who_have_interest_on_me, - TEN_UNUSED void *on_closed_data) { - // TEN_NOLINTNEXTLINE(thread-check) - // thread-check: This function is always called in threads other than the - // thread where ten_closeable_t resides. - TEN_ASSERT(self && ten_closeable_check_integrity(self, false), - "Invalid argument."); - TEN_ASSERT(self->be_notified_resources.on_closed_done_mode == - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_OUT_OWN_THREAD, - "Should not happen."); - - size_t remain_on_closed_done_count = 0; - TEN_DO_WITH_MUTEX_LOCK(self->be_notified_resources.on_closed_done_mutex, { - remain_on_closed_done_count = - --self->be_notified_resources.expected_on_closed_done_count; - }); - - if (remain_on_closed_done_count == 0) { - ten_closeable_on_closed_all_done(self); - } -} - void ten_closeable_action_to_close_myself_done( ten_closeable_t *self, TEN_UNUSED void *on_close_myself_data) { TEN_ASSERT(self && ten_closeable_check_integrity(self, true), "Invalid argument."); - self->state = TEN_CLOSEABLE_STATE_CLOSED; - - if (ten_list_is_empty(&self->be_notified_resources.on_closed_queue)) { - ten_closeable_on_closed_all_done(self); - return; - } - - // Under different modes, the logic for determining the receipt of all - // on_closed_done() is different. - if (self->be_notified_resources.on_closed_done_mode == - TEN_CLOSEABLE_ON_CLOSED_DONE_MODE_OUT_OWN_THREAD) { - self->be_notified_resources.expected_on_closed_done_count = - ten_list_size(&self->be_notified_resources.on_closed_queue); - - self->be_notified_resources.on_closed_done_cb = - ten_closeable_on_closed_done_out_of_thread; - } else { - self->be_notified_resources.on_closed_done_cb = - ten_closeable_on_closed_done; - } - - // Notify others who are interested in my 'closed' event. - ten_list_foreach (&self->be_notified_resources.on_closed_queue, iter) { - ten_closeable_on_closed_item_t *item = ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item && item->on_closed_cb, "Should not happen."); - - item->on_closed_cb(self, item->who_have_interest_on_me, - item->on_closed_data, - self->be_notified_resources.on_closed_done_cb); - } -} - -/** - * @brief All the underlying resources are closed, so I could start to close - * myself. - */ -static void ten_closeable_do_close(ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - if (self->action_to_close_myself.action_to_close_myself_cb) { - self->action_to_close_myself.action_to_close_myself_cb( - self, self->action_to_close_myself.action_to_close_myself_data, - ten_closeable_action_to_close_myself_done); - } else { - // There is no customized close_myself actions, so call - // 'action_to_close_myself_done' directly. - ten_closeable_action_to_close_myself_done(self, NULL); - } + ten_closeable_on_closed_all_done(self); } static void ten_closeable_on_closed_all_done_item_destroy( @@ -292,22 +126,3 @@ void ten_closeable_add_be_notified( ten_closeable_on_closed_all_done_item_destroy); } } - -void ten_closeable_close(ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - TEN_ASSERT(self->state < TEN_CLOSEABLE_STATE_CLOSING, - "The 'close()' function could be called only once to ensure that " - "all the resources are closed from top to bottom."); - - self->state = TEN_CLOSEABLE_STATE_CLOSING; - - ten_closeable_do_close(self); -} - -bool ten_closeable_is_closed(ten_closeable_t *self) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - return self->state == TEN_CLOSEABLE_STATE_CLOSED; -} diff --git a/core/src/ten_runtime/protocol/close.c b/core/src/ten_runtime/protocol/close.c index 0374dd022..6cb45b056 100644 --- a/core/src/ten_runtime/protocol/close.c +++ b/core/src/ten_runtime/protocol/close.c @@ -115,31 +115,10 @@ void ten_protocol_set_on_closed(ten_protocol_t *self, self->on_closed_data = on_closed_data; } -/** - * @brief The overall closing flow is as follows. - * - * ten_protocol_close - * => close implemented protocol - * (when the implementation protocol is closed) - * => ten_protocol_on_close - */ void ten_protocol_close(ten_protocol_t *self) { TEN_ASSERT(self, "Should not happen."); TEN_ASSERT(ten_protocol_check_integrity(self, true), "Should not happen."); - // As a design principle, the resources must be closed from top to bottom. So - // the 'ten_protocol_close()' is expected to be called in the connection - // (i.e., a 'ten_connection_t' object, and the protocol is used in - // communication) or app (i.e., a 'ten_app_t' object, and the protocol is used - // as endpoint). - // - // The brief closing flow is as follows: - // - // ten_connection_close() - // => ten_protocol_close() - // => ten_closeable_close() - // => ten_protocol_action_to_close_myself() - // => ten_protocol_t::close() // closes the implementation if (ten_atomic_bool_compare_swap(&self->is_closing, 0, 1)) { switch (self->role) { case TEN_PROTOCOL_ROLE_LISTEN: @@ -158,26 +137,10 @@ void ten_protocol_close(ten_protocol_t *self) { break; } - // TODO(Wei): Change to intend_to_close()? - ten_closeable_close(&self->closeable); + self->close(self); } } -/** - * TODO(Wei): After the implementation protocol implements the 'ten_closeable_t' - * interface, refine this function accordingly. - */ -void ten_protocol_action_to_close_myself( - ten_closeable_t *self_, TEN_UNUSED void *close_myself_data, - TEN_UNUSED ten_closeable_action_to_close_myself_done_func_t - close_myself_done) { - ten_protocol_t *self = CONTAINER_OF_FROM_OFFSET(self_, self_->offset_in_impl); - TEN_ASSERT(self && ten_protocol_check_integrity(self, true), - "Should not happen."); - - self->close(self); -} - void ten_protocol_on_impl_intends_to_close( ten_closeable_t *impl, void *self_closeable, TEN_UNUSED void *on_intend_to_close_data) { diff --git a/core/src/ten_runtime/protocol/integrated/protocol_integrated.c b/core/src/ten_runtime/protocol/integrated/protocol_integrated.c index b45a25dad..2d32320ad 100644 --- a/core/src/ten_runtime/protocol/integrated/protocol_integrated.c +++ b/core/src/ten_runtime/protocol/integrated/protocol_integrated.c @@ -668,11 +668,6 @@ void ten_protocol_integrated_init( (ten_protocol_migrate_func_t)ten_protocol_integrated_migrate, (ten_protocol_clean_func_t)ten_protocol_integrated_clean); - // TODO(Wei): If the implementation protocol implements 'ten_closeable_t' - // interface, change the following logic accordingly. - ten_closeable_set_action_to_close_myself( - &self->base.closeable, ten_protocol_action_to_close_myself, NULL); - ten_closeable_add_be_notified(&self->base.closeable, &self->base.closeable, ten_protocol_on_impl_closed_all_done, NULL); From d6f8b000b4666386ba1d8587a4ed40b27ff1d82d Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Thu, 14 Nov 2024 17:38:42 +0800 Subject: [PATCH 4/4] refactor: remove unused codes on closeable_t --- .../ten_runtime/common/closeable.h | 170 ------------------ .../ten_runtime/protocol/close.h | 8 - .../ten_runtime/protocol/protocol.h | 3 - core/src/ten_runtime/common/closeable.c | 128 ------------- core/src/ten_runtime/protocol/close.c | 76 +------- .../protocol/integrated/protocol_integrated.c | 4 - core/src/ten_runtime/protocol/protocol.c | 8 - 7 files changed, 6 insertions(+), 391 deletions(-) delete mode 100644 core/include_internal/ten_runtime/common/closeable.h delete mode 100644 core/src/ten_runtime/common/closeable.c diff --git a/core/include_internal/ten_runtime/common/closeable.h b/core/include_internal/ten_runtime/common/closeable.h deleted file mode 100644 index c415f7f6a..000000000 --- a/core/include_internal/ten_runtime/common/closeable.h +++ /dev/null @@ -1,170 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// -#pragma once - -#include "ten_runtime/ten_config.h" - -#include "ten_utils/container/list.h" -#include "ten_utils/lib/signature.h" -#include "ten_utils/sanitizer/thread_check.h" - -#define TEN_CLOSEABLE_SIGNATURE 0x7263656c6f736564U - -typedef struct ten_closeable_t ten_closeable_t; - -/** - * @brief This function is used to notify others (i.e., @a - * who_have_interest_on_me) who are interested in the 'on_closed_all_done' event - * of mine. - * - * @param self The instance who implements the 'ten_closeable_t' interface. - * @param who_have_interest_on_me The instance who is interested in the - * 'on_closed_all_done' event of mine. - * @param on_closed_all_done_data The data bound to the 'on_closed_all_done' - * callback. - * - * @note @a self might be destroyed by its owner after its owner receives the - * 'on_closed_all_done' event, so it's not safe for others to access the memory - * of @a self in this callback. - */ -typedef void (*ten_closeable_on_closed_all_done_func_t)( - ten_closeable_t *self, void *who_have_interest_on_me, - void *on_closed_all_done_data); - -typedef struct ten_closeable_on_closed_all_done_item_t { - void *who_have_interest_on_me; - ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb; - void *on_closed_all_done_data; -} ten_closeable_on_closed_all_done_item_t; - -/** - * @brief This structure is used to collect information about which other - * instances, as well as their interest in which closing events of a - * ten_closeable_t instance. - * - * @note Someone is not always interested in all closing events of mine, so we - * prefer to use three different queues here. - */ -typedef struct ten_closeable_be_notified_resources_t { - // Is interested in 'closed_all_done' event. The type of the element is - // 'ten_closeable_on_closed_all_done_item_t'. - ten_list_t on_closed_all_done_queue; -} ten_closeable_be_notified_resources_t; - -/** - * @brief The standard interface for closing a resource. - * - * Basically, if A wants to be closed, there are some stages during the closing - * flow. - * - * 1) Stage: Make a 'intend_to_close' announcement. - * In this stage, a 'ten_closeable_t' tries to announce the intend_to_close - * event to all others who are interested in this event. - * - * 2) Stage: Determine the closing root. - * In this stage, all possible closing roots will be determined. - * - * 3) Stage: Start to close. - * In this stage, the closing flow will be started from all roots. - * - * 4) Stage: Close owned 'ten_closeable_t' resources. - * In this stage, all owned 'ten_closeable_t' resources of a - * 'ten_closeable_t' are closed. - * - * 5) Stage: Close owned non-'ten_closeable_t' resources. - * In this stage, all owned non-'ten_closeable_t' resources of a - * 'ten_closeable_t' are closed. - * - * 6) Stage: On closed, make a 'closed' announcement. - * When a 'ten_closeable_t' is closed completed, it will notify others, who - * are interested in my 'closed' event, that I am closed. - * - * 7) Stage: All subscribers interested in the 'on_closed' event have completed - * handling the 'on_closed' event, then make a 'on_closed_all_done' - * announcement. In other words, when a 'ten_closeable_t' receives all the - * 'on_closed_done' callbacks, it will notify others who are interested in my - * 'on_closed_all_done' event. Please note that this 'ten_closeable_t' might - * be destroyed in this stage by its owner. - */ -typedef struct ten_closeable_t { - ten_signature_t signature; - - // All operations _must_ be called in the same thread. - ten_sanitizer_thread_check_t thread_check; - - // The offset of this 'ten_closeable_t' object in the implementation who - // implements the 'ten_closeable_t' interface. It will be used to get the raw - // pointer of the implementation. - // - // We want to use the following coding style to ensure that the - // 'implementation' is paired one-to-one with 'ten_closeable_t'. - // - // - The 'ten_closeable_t' is an embedded member of 'implementation' rather - // than a pointer. - // - // Ex: - // struct some_impl_t { - // // other fields. - // - // ten_closeable_t closeable; - // - // // other fields. - // } - // - // The above example is similar to the following codes in other programming - // language: - // - // class some_impl_t implements ten_closeable_t; - // - // We want to represent the following two key points: - // - // 1. The implementation is a kind of 'ten_closeable_t'. - // - // 2. One 'ten_closeable_t' could only be paired with one implementation. The - // implementation is closing when its embedded 'ten_closeable_t' is - // closing; the implementation is closed when its embedded - // 'ten_closeable_t' is closed. - // - // So we keep the offset rather than the raw pointer here. - ptrdiff_t offset_in_impl; - - // This list is used to store those who are interested in my 'closed' events. - ten_closeable_be_notified_resources_t be_notified_resources; -} ten_closeable_t; - -TEN_RUNTIME_API bool ten_closeable_check_integrity(ten_closeable_t *self, - bool thread_check); - -/** - * @example An implementation whose name is 'some_impl_t' and the name of the - * 'ten_closeable_t' field in it is 'closeable'. The calling of this function in - * the implementation will be as follows: - * - * ten_closeable_init(&impl->closeable, - * offsetof(some_impl_t, closeable))) - */ -TEN_RUNTIME_API void ten_closeable_init(ten_closeable_t *self, - ptrdiff_t offset); - -TEN_RUNTIME_API void ten_closeable_deinit(ten_closeable_t *self); - -/** - * @note Add @a who_have_interest_on_me who is interested in my various closing - * event to the closeable management of mine (i.e., @a self). - * - * @param self The instance who implements the 'ten_closeable_t' interface. - * @param who_have_interest_on_me The instance who is interested in various - * closing event of @a self. - */ -TEN_RUNTIME_API void ten_closeable_add_be_notified( - ten_closeable_t *self, void *who_have_interest_on_me, - // closed_all_done event. - ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb, - void *on_closed_all_done_data); - -TEN_RUNTIME_API void ten_closeable_action_to_close_myself_done( - ten_closeable_t *self, void *on_close_myself_data); diff --git a/core/include_internal/ten_runtime/protocol/close.h b/core/include_internal/ten_runtime/protocol/close.h index 86b44fb07..547a23d50 100644 --- a/core/include_internal/ten_runtime/protocol/close.h +++ b/core/include_internal/ten_runtime/protocol/close.h @@ -10,8 +10,6 @@ #include -#include "include_internal/ten_runtime/common/closeable.h" - typedef struct ten_protocol_t ten_protocol_t; typedef void (*ten_protocol_on_closed_func_t)(ten_protocol_t *self, @@ -26,9 +24,3 @@ TEN_RUNTIME_PRIVATE_API void ten_protocol_set_on_closed( void *on_closed_data); TEN_RUNTIME_PRIVATE_API void ten_protocol_on_close(ten_protocol_t *self); - -TEN_RUNTIME_API void ten_protocol_on_impl_intends_to_close( - ten_closeable_t *impl, void *self_closeable, void *on_intend_to_close_data); - -TEN_RUNTIME_API void ten_protocol_on_impl_closed_all_done( - ten_closeable_t *impl, void *self_closeable, void *on_closed_all_done_data); diff --git a/core/include_internal/ten_runtime/protocol/protocol.h b/core/include_internal/ten_runtime/protocol/protocol.h index 7374e0f06..901c51986 100644 --- a/core/include_internal/ten_runtime/protocol/protocol.h +++ b/core/include_internal/ten_runtime/protocol/protocol.h @@ -8,7 +8,6 @@ #include "ten_runtime/ten_config.h" -#include "include_internal/ten_runtime/common/closeable.h" #include "include_internal/ten_runtime/protocol/close.h" #include "ten_runtime/protocol/protocol.h" #include "ten_utils/container/list.h" @@ -75,8 +74,6 @@ typedef struct ten_protocol_t { */ ten_sanitizer_thread_check_t thread_check; - ten_closeable_t closeable; - ten_ref_t ref; ten_addon_host_t *addon_host; diff --git a/core/src/ten_runtime/common/closeable.c b/core/src/ten_runtime/common/closeable.c deleted file mode 100644 index 7cc476fd5..000000000 --- a/core/src/ten_runtime/common/closeable.c +++ /dev/null @@ -1,128 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// -#include "include_internal/ten_runtime/common/closeable.h" - -#include "ten_utils/container/list.h" -#include "ten_utils/container/list_node.h" -#include "ten_utils/container/list_node_ptr.h" -#include "ten_utils/container/list_ptr.h" -#include "ten_utils/lib/signature.h" -#include "ten_utils/macro/check.h" -#include "ten_utils/macro/mark.h" -#include "ten_utils/macro/memory.h" -#include "ten_utils/sanitizer/thread_check.h" - -bool ten_closeable_check_integrity(ten_closeable_t *self, bool thread_check) { - TEN_ASSERT(self, "Invalid argument."); - - if (ten_signature_get(&self->signature) != TEN_CLOSEABLE_SIGNATURE) { - return false; - } - - if (thread_check) { - return ten_sanitizer_thread_check_do_check(&self->thread_check); - } - - return true; -} - -static void ten_closeable_be_notified_resources_init( - ten_closeable_be_notified_resources_t *self) { - TEN_ASSERT(self, "Invalid argument."); - - ten_list_init(&self->on_closed_all_done_queue); -} - -void ten_closeable_init(ten_closeable_t *self, ptrdiff_t offset) { - TEN_ASSERT(self, "Invalid argument."); - - ten_signature_set(&self->signature, (ten_signature_t)TEN_CLOSEABLE_SIGNATURE); - ten_sanitizer_thread_check_init_with_current_thread(&self->thread_check); - - self->offset_in_impl = offset; - - ten_closeable_be_notified_resources_init(&self->be_notified_resources); -} - -static void ten_closeable_be_notified_resources_deinit( - ten_closeable_be_notified_resources_t *self) { - TEN_ASSERT(self, "Invalid argument."); - - ten_list_clear(&self->on_closed_all_done_queue); -} - -void ten_closeable_deinit(ten_closeable_t *self) { - // TEN_NOLINTNEXTLINE(thread-check) - // thread-check: The belonging thread (i.e., ten_thread_t object) maybe - // already destroyed, so do not check thread integrity. - TEN_ASSERT(self && ten_closeable_check_integrity(self, false), - "Invalid argument."); - - ten_signature_set(&self->signature, 0); - ten_sanitizer_thread_check_deinit(&self->thread_check); - - ten_closeable_be_notified_resources_deinit(&self->be_notified_resources); -} - -static void ten_closeable_on_closed_all_done(ten_closeable_t *self) { - TEN_ASSERT(self, "Should not happen."); - TEN_ASSERT(ten_closeable_check_integrity(self, true), "Invalid argument."); - - ten_list_t on_closed_all_done_queue = TEN_LIST_INIT_VAL; - - ten_list_swap(&on_closed_all_done_queue, - &self->be_notified_resources.on_closed_all_done_queue); - - ten_list_foreach (&on_closed_all_done_queue, iter) { - ten_closeable_on_closed_all_done_item_t *item = - ten_ptr_listnode_get(iter.node); - TEN_ASSERT(item && item->on_closed_all_done_cb, "Should not happen."); - - item->on_closed_all_done_cb(self, item->who_have_interest_on_me, - item->on_closed_all_done_data); - }; - - ten_list_clear(&on_closed_all_done_queue); -} - -void ten_closeable_action_to_close_myself_done( - ten_closeable_t *self, TEN_UNUSED void *on_close_myself_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - ten_closeable_on_closed_all_done(self); -} - -static void ten_closeable_on_closed_all_done_item_destroy( - ten_closeable_on_closed_all_done_item_t *self) { - TEN_ASSERT(self, "Invalid argument."); - - TEN_FREE(self); -} - -void ten_closeable_add_be_notified( - ten_closeable_t *self, void *who_have_interest_on_me, - ten_closeable_on_closed_all_done_func_t on_closed_all_done_cb, - void *on_closed_all_done_data) { - TEN_ASSERT(self && ten_closeable_check_integrity(self, true), - "Invalid argument."); - - if (on_closed_all_done_cb) { - ten_closeable_on_closed_all_done_item_t *item = - TEN_MALLOC(sizeof(ten_closeable_on_closed_all_done_item_t)); - TEN_ASSERT(item, "Failed to allocate memory."); - - item->who_have_interest_on_me = who_have_interest_on_me; - item->on_closed_all_done_cb = on_closed_all_done_cb; - item->on_closed_all_done_data = on_closed_all_done_data; - - ten_list_push_ptr_back( - &self->be_notified_resources.on_closed_all_done_queue, item, - (ten_ptr_listnode_destroy_func_t) - ten_closeable_on_closed_all_done_item_destroy); - } -} diff --git a/core/src/ten_runtime/protocol/close.c b/core/src/ten_runtime/protocol/close.c index 6cb45b056..b81c91054 100644 --- a/core/src/ten_runtime/protocol/close.c +++ b/core/src/ten_runtime/protocol/close.c @@ -6,12 +6,9 @@ // #include "ten_runtime/protocol/close.h" -#include "include_internal/ten_runtime/common/closeable.h" #include "include_internal/ten_runtime/protocol/protocol.h" #include "ten_utils/log/log.h" #include "ten_utils/macro/check.h" -#include "ten_utils/macro/field.h" -#include "ten_utils/macro/mark.h" // The relationship of the protocol chain is as follows. // @@ -85,7 +82,12 @@ void ten_protocol_on_close(ten_protocol_t *self) { } TEN_LOGD("Close base protocol."); - ten_closeable_action_to_close_myself_done(&self->closeable, NULL); + self->is_closed = true; + + if (self->on_closed) { + // Call the registered on_closed callback when the base protocol is closed. + self->on_closed(self, self->on_closed_data); + } } bool ten_protocol_is_closing(ten_protocol_t *self) { @@ -140,69 +142,3 @@ void ten_protocol_close(ten_protocol_t *self) { self->close(self); } } - -void ten_protocol_on_impl_intends_to_close( - ten_closeable_t *impl, void *self_closeable, - TEN_UNUSED void *on_intend_to_close_data) { - TEN_ASSERT(impl && ten_closeable_check_integrity(impl, true), - "Access across threads."); - - ten_closeable_t *closeable = (ten_closeable_t *)self_closeable; - TEN_ASSERT(closeable && ten_closeable_check_integrity(closeable, true), - "Access across threads."); - - ten_protocol_t *self = - CONTAINER_OF_FROM_OFFSET(closeable, closeable->offset_in_impl); - TEN_ASSERT(self && ten_protocol_check_integrity(self, true), - "Should not happen."); - - bool to_close_protocol = false; - - if (self->role == TEN_PROTOCOL_ROLE_IN_EXTERNAL) { - // If the protocol (i.e., self) is created when the server accepts a client - // outside of the ten world (ex: browser), we can not do anything except - // closing the protocol and its bound resources, and expect the client to - // handle the situation such as reconnecting. - to_close_protocol = true; - } - - if (self->cascade_close_upward) { - // If the 'cascade_close_upward' flag is true, which means the protocol (the - // implementation protocol who owns the physical connection) will be closed - // automatically when the underlying lower layers are closed. As a - // principle, the protocol (the 'ten_protocol_t') could only be closed from - // the runtime side. In other words, the implementation protocol owns its - // underlying resources such as the physical connections, but the life cycle - // (ex: closing and destroying) of the protocols (the 'ten_protocol_t') are - // managed by the runtime. - to_close_protocol = true; - } - - if (to_close_protocol) { - // TODO(Liu): Pass the 'intend_to_close' event to the owner (i.e., - // ten_connection_t or ten_app_t) of the protocol after they implement the - // closeable interface. - ten_protocol_close(self); - } -} - -void ten_protocol_on_impl_closed_all_done( - TEN_UNUSED ten_closeable_t *impl, void *self_closeable, - TEN_UNUSED void *on_closed_all_done_data) { - ten_closeable_t *closeable = (ten_closeable_t *)self_closeable; - TEN_ASSERT(closeable && ten_closeable_check_integrity(closeable, true), - "Access across threads."); - - ten_protocol_t *self = - CONTAINER_OF_FROM_OFFSET(closeable, closeable->offset_in_impl); - TEN_ASSERT(self && ten_protocol_check_integrity(self, true), - "Should not happen."); - TEN_ASSERT(!self->is_closed, "Should not happen."); - - self->is_closed = true; - - if (self->on_closed) { - // Call the registered on_closed callback when the base protocol is closed. - self->on_closed(self, self->on_closed_data); - } -} diff --git a/core/src/ten_runtime/protocol/integrated/protocol_integrated.c b/core/src/ten_runtime/protocol/integrated/protocol_integrated.c index 2d32320ad..ffb95474d 100644 --- a/core/src/ten_runtime/protocol/integrated/protocol_integrated.c +++ b/core/src/ten_runtime/protocol/integrated/protocol_integrated.c @@ -10,7 +10,6 @@ #include "include_internal/ten_runtime/addon/protocol/protocol.h" #include "include_internal/ten_runtime/app/app.h" #include "include_internal/ten_runtime/app/migration.h" -#include "include_internal/ten_runtime/common/closeable.h" #include "include_internal/ten_runtime/connection/connection.h" #include "include_internal/ten_runtime/connection/migration.h" #include "include_internal/ten_runtime/engine/engine.h" @@ -668,9 +667,6 @@ void ten_protocol_integrated_init( (ten_protocol_migrate_func_t)ten_protocol_integrated_migrate, (ten_protocol_clean_func_t)ten_protocol_integrated_clean); - ten_closeable_add_be_notified(&self->base.closeable, &self->base.closeable, - ten_protocol_on_impl_closed_all_done, NULL); - self->base.role = TEN_PROTOCOL_ROLE_INVALID; self->base.on_cleaned_for_external = ten_protocol_integrated_on_base_protocol_cleaned; diff --git a/core/src/ten_runtime/protocol/protocol.c b/core/src/ten_runtime/protocol/protocol.c index 4a10fe8a8..8557f89e7 100644 --- a/core/src/ten_runtime/protocol/protocol.c +++ b/core/src/ten_runtime/protocol/protocol.c @@ -9,7 +9,6 @@ #include "include_internal/ten_runtime/addon/addon.h" #include "include_internal/ten_runtime/addon/protocol/protocol.h" #include "include_internal/ten_runtime/app/app.h" -#include "include_internal/ten_runtime/common/closeable.h" #include "include_internal/ten_runtime/common/constant_str.h" #include "include_internal/ten_runtime/connection/connection.h" #include "include_internal/ten_runtime/connection/migration.h" @@ -108,8 +107,6 @@ void ten_protocol_init(ten_protocol_t *self, const char *name, ten_signature_set(&self->signature, (ten_signature_t)TEN_PROTOCOL_SIGNATURE); - ten_closeable_init(&self->closeable, offsetof(ten_protocol_t, closeable)); - ten_sanitizer_thread_check_init_with_current_thread(&self->thread_check); self->addon_host = NULL; @@ -166,8 +163,6 @@ void ten_protocol_deinit(ten_protocol_t *self) { ten_signature_set(&self->signature, 0); - ten_closeable_deinit(&self->closeable); - self->attach_to = TEN_PROTOCOL_ATTACH_TO_INVALID; self->attached_target.app = NULL; self->attached_target.connection = NULL; @@ -424,9 +419,6 @@ void ten_protocol_update_belonging_thread_on_cleaned(ten_protocol_t *self) { &self->thread_check); TEN_ASSERT(ten_protocol_check_integrity(self, true), "Access across threads."); - - ten_sanitizer_thread_check_set_belonging_thread_to_current_thread( - &self->closeable.thread_check); } void ten_protocol_set_addon(ten_protocol_t *self,