diff --git a/src/ctxt/ctxt.c b/src/ctxt/ctxt.c index b04e9d6..2519f24 100644 --- a/src/ctxt/ctxt.c +++ b/src/ctxt/ctxt.c @@ -68,14 +68,15 @@ void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* init_rgn) ASSERT(ax->bac != NULL, "backend wasn't initialized"); } +static void shutdown(struct msgq* mq, pthread_t thid); + void ax__ctxt_cleanup(struct ax_ctxt* ax) { - struct msgq* bac_mq = ax__backend_msgq(ax->bac); - msgq_begin_send_typed(bac_mq, ax_msg_shutdown); - msgq_end_send(bac_mq); - ax_log(ax, "waiting for backend shutdown."); - pthread_join(ax->bac_thid, NULL); - ax_log(ax, "backend shutdown"); + shutdown(ax__backend_msgq(ax->bac), ax->bac_thid); + + if (ax->log_auto_close) { + fclose(ax->log_out); + } } /* ----------------------------------------------------------------------------- @@ -258,3 +259,10 @@ cleanup: rgn_cleanup(bac_rgn); return NULL; } + +static void shutdown(struct msgq* mq, pthread_t thid) +{ + (void) msgq_begin_send_typed(mq, ax_msg_shutdown); + msgq_end_send(mq); + pthread_join(thid, NULL); +}