Skip to content

Commit

Permalink
aio: separate stop / shutdown from fini (deallocate)
Browse files Browse the repository at this point in the history
Probably other subsystems should get the same treatment.  We need
to basically start the process of shutting down so that subsystems
know to cease operation before we rip memory out from underneath them.

This ensures that no new operations can be started as well, once we
have begun the process of teardown.
  • Loading branch information
gdamore committed Dec 7, 2024
1 parent c6c01bc commit dedfd30
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/core/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,17 @@ nni_sleep_aio(nng_duration ms, nng_aio *aio)
}
}

static void
nni_aio_expire_q_stop(nni_aio_expire_q *eq)
{
if (eq != NULL && !eq->eq_exit) {
nni_mtx_lock(&eq->eq_mtx);
eq->eq_exit = true;
nni_cv_wake(&eq->eq_cv);
nni_mtx_unlock(&eq->eq_mtx);
}
}

static void
nni_aio_expire_q_free(nni_aio_expire_q *eq)
{
Expand Down Expand Up @@ -810,6 +821,14 @@ nni_aio_expire_q_alloc(void)
return (eq);
}

void
nni_aio_sys_stop(void)
{
for (int i = 0; i < nni_aio_expire_q_cnt; i++) {
nni_aio_expire_q_stop(nni_aio_expire_q_list[i]);
}
}

void
nni_aio_sys_fini(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/core/aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ extern void nni_aio_completions_add(
nni_aio_completions *, nni_aio *, int, size_t);

extern int nni_aio_sys_init(nng_init_params *);
extern void nni_aio_sys_stop(void);
extern void nni_aio_sys_fini(void);

typedef struct nni_aio_expire_q nni_aio_expire_q;
Expand Down
3 changes: 2 additions & 1 deletion src/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ nng_fini(void)
nni_atomic_flag_reset(&init_busy);
return;
}
nni_aio_sys_stop(); // no more scheduling allowed!
nni_sock_closeall();
nni_sp_tran_sys_fini();
nni_tls_sys_fini();
nni_reap_drain();
nni_aio_sys_fini();
nni_taskq_sys_fini();
nni_reap_sys_fini(); // must be before timer and aio (expire)
nni_id_map_sys_fini();
nni_reap_sys_fini(); // must be near the end
nni_plat_fini();
nni_atomic_flag_reset(&init_busy);
}

0 comments on commit dedfd30

Please sign in to comment.