Skip to content

Commit

Permalink
fix: refine some codes
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Jan 8, 2025
1 parent bf07081 commit 2566a16
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 0 additions & 4 deletions core/include_internal/ten_runtime/addon_loader/addon_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ TEN_RUNTIME_API ten_addon_loader_t *ten_addon_loader_create(

TEN_RUNTIME_API void ten_addon_loader_destroy(ten_addon_loader_t *self);

TEN_RUNTIME_PRIVATE_API void ten_addon_loader_init(ten_addon_loader_t *self);

TEN_RUNTIME_PRIVATE_API void ten_addon_loader_deinit(ten_addon_loader_t *self);

TEN_RUNTIME_PRIVATE_API void ten_addon_loader_load_addon(
ten_addon_loader_t *self, TEN_ADDON_TYPE addon_type,
const char *addon_name);
11 changes: 9 additions & 2 deletions core/src/ten_runtime/addon/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,21 @@ ten_addon_t *ten_addon_unregister(ten_addon_store_t *store,
return ten_addon_store_del(store, addon_name);
}

static void ten_addon_unregister_all(void) {
static void ten_addon_unregister_all_except_addon_loader_addon(void) {
ten_addon_unregister_all_extension();
ten_addon_unregister_all_extension_group();
ten_addon_unregister_all_protocol();
}

void ten_unregister_all_addons_and_cleanup(void) {
ten_addon_unregister_all();
// Since Python addons (e.g., Python extension addons) require access to the
// Python VM when performing `addon_t` deinitialization, and the Python addon
// loader will destroy the Python VM during its own destruction, the Python
// addon loader must only be unloaded after all other non-addon-loader types
// of addons have been fully unloaded. Only then can the addon loader itself
// be unloaded.

ten_addon_unregister_all_except_addon_loader_addon();

// Destroy all addon loaders' singleton to avoid memory leak.
ten_addon_loader_addons_destroy_singleton_instance();
Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_runtime/addon/addon_autoload.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ bool ten_addon_try_load_specific_addon_using_all_addon_loaders(
TEN_ASSERT(addon_loader, "Should not happen.");

if (addon_loader) {
addon_loader->on_load_addon(addon_loader, addon_type, addon_name);
ten_addon_loader_load_addon(addon_loader, addon_type, addon_name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/ten_runtime/addon_loader/addon_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void ten_addon_loader_destroy(ten_addon_loader_t *self) {
TEN_FREE(self);
}

void ten_addon_loader_init(ten_addon_loader_t *self) {
static void ten_addon_loader_init(ten_addon_loader_t *self) {
TEN_ASSERT(self && ten_addon_loader_check_integrity(self),
"Invalid argument.");

Expand All @@ -66,7 +66,7 @@ void ten_addon_loader_init(ten_addon_loader_t *self) {
}
}

void ten_addon_loader_deinit(ten_addon_loader_t *self) {
static void ten_addon_loader_deinit(ten_addon_loader_t *self) {
TEN_ASSERT(self && ten_addon_loader_check_integrity(self),
"Invalid argument.");

Expand Down

0 comments on commit 2566a16

Please sign in to comment.