From 982bccb9e18092d596effd1eb13cd607865f39f9 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 24 Feb 2011 16:58:36 +0100 Subject: [PATCH] Destroy forb in the correct order This is to avoid deadlocks during forb_destroy(). --- src/forb/src/forb.c | 19 ++++++++++++++++--- src/frsh/frsh_api/frsh_core.c | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/forb/src/forb.c b/src/forb/src/forb.c index 79759dad..376651f4 100644 --- a/src/forb/src/forb.c +++ b/src/forb/src/forb.c @@ -300,6 +300,22 @@ void forb_destroy(forb_orb orb) forb_t *forb = forb_object_to_forb(orb); forb_port_t *port; forb_regref_t *regref; + forb_object obj; + + /* Destroy ports to prevent remote requests from coming */ + ul_list_for_each_cut(forb_port, forb, port) { + forb_destroy_port(port); + } + + /* Wait for executors to finish all requests (and thus close + * connections to peers). This is very inefficient for big + * number of objects, but we do not care */ + gavl_cust_for_each(forb_objects_nolock, forb, obj) { + forb_executor_t *executor; + executor = forb_object_get_executor(obj); + if (executor) + forb_executor_synchronize(executor); + } pthread_cancel(forb->execution_thread.pthread_id); pthread_join(forb->execution_thread.pthread_id, NULL); @@ -309,9 +325,6 @@ void forb_destroy(forb_orb orb) forb_unregister_reference(orb, regref->name.str); } - ul_list_for_each_cut(forb_port, forb, port) { - forb_destroy_port(port); - } forb_object_release(orb); forb_free(forb); } diff --git a/src/frsh/frsh_api/frsh_core.c b/src/frsh/frsh_api/frsh_core.c index 3ad34b73..1e17525f 100644 --- a/src/frsh/frsh_api/frsh_core.c +++ b/src/frsh/frsh_api/frsh_core.c @@ -161,10 +161,11 @@ err: void frsh_destroy() { + forb_destroy(frsh_forb_global.orb); + pthread_cancel(frsh_forb_global.alloc_executor_thread.pthread_id); pthread_join(frsh_forb_global.alloc_executor_thread.pthread_id, NULL); - forb_destroy(frsh_forb_global.orb); /* TODO: Destroy all FRAs etc. */ } -- 2.39.2