fixup! fixup! WIP: Add loopmgr that replaces isc_app, and parts of isc_nm related to the uv_loops

This commit is contained in:
Evan Hunt
2022-03-30 11:18:23 -07:00
parent 0f5fd80ffc
commit ece94d6936
2 changed files with 52 additions and 4 deletions

View File

@@ -81,25 +81,41 @@ isc_loopmgr_run(isc_loopmgr_t *loopmgr);
* Requires:
*\li 'loopmgr' is a valid loop manager.
*/
void
isc_loop_runjob(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
/*%<
* Schedule a single job to run in 'loop' in the next iteration
* of uv_run(): 'cb' will be called with argument 'cbarg'.
*
* Requires:
*\li 'loop' is a valid loop.
*\li 'loop' is the currently running loop, or the loop manager
* associated with 'loop' is paused or has not yet been started.
*/
void
isc_loopmgr_pause(isc_loopmgr_t *loopmgr);
/*%<
* Send pause events to all running loops in 'loopmgr' (except the
* current one if called from one of the loops). All paused loops will
* wait utnil isc_loopmgr_resume() is called before continuing.
* Send pause events to all running loops in 'loopmgr' except the
* current one. This can only be called from a running loop.
* All the paused loops will wait until isc_loopmgr_resume() is
* run in the calling loop before continuing.
*
* Requires:
*\li 'loopmgr' is a valid loop manager.
*\li We are in a running loop.
*/
void
isc_loopmgr_resume(isc_loopmgr_t *loopmgr);
/*%<
* Send resume events to all paused loops in 'loopmgr'.
* Send resume events to all paused loops in 'loopmgr'. This can
* only be called by a running loop (which must therefore be the
* loop that called isc_loopmgr_pause()).
*
* Requires:
*\li 'loopmgr' is a valid loop manager.
*\li We are in a running loop.
*/
void

View File

@@ -370,6 +370,36 @@ isc_loopmgr_teardown(isc_loopmgr_t *loopmgr, isc_job_cb cb, void *cbarg) {
isc__loopmgr_schedule(loopmgr, isc_loop_dtor, cb, cbarg);
}
void
isc_loop_runjob(isc_loop_t *loop, isc_job_cb cb, void *cbarg) {
isc_loopmgr_t *loopmgr = NULL;
isc_job_t *job = NULL;
int r;
REQUIRE(VALID_LOOP(loop));
loopmgr = loop->loopmgr;
REQUIRE(loop->tid == isc__loopmgr_tid_v ||
!atomic_load(&loopmgr->running) ||
atomic_load(&loopmgr->paused));
job = isc_mem_get(loop->mctx, sizeof(*job));
*job = (isc_job_t){
.cb = cb,
.cbarg = cbarg,
};
isc_mem_attach(loop->mctx, &job->mctx);
r = uv_idle_init(&loop->loop, &job->idle);
UV_RUNTIME_CHECK(uv_idle_init, r);
uv_handle_set_data((uv_handle_t *)&job->idle, job);
r = uv_idle_start(&job->idle, isc__job_cb);
UV_RUNTIME_CHECK(uv_idle_start, r);
}
void
isc_loopmgr_run(isc_loopmgr_t *loopmgr) {
REQUIRE(VALID_LOOPMGR(loopmgr));
@@ -396,6 +426,7 @@ isc_loopmgr_run(isc_loopmgr_t *loopmgr) {
void
isc_loopmgr_pause(isc_loopmgr_t *loopmgr) {
REQUIRE(VALID_LOOPMGR(loopmgr));
REQUIRE(isc__loopmgr_tid_v != ISC_LOOPMGR_TID_UNKNOWN);
for (size_t i = 0; i < loopmgr->nloops; i++) {
isc_loop_t *loop = &loopmgr->loops[i];
@@ -415,6 +446,7 @@ isc_loopmgr_pause(isc_loopmgr_t *loopmgr) {
void
isc_loopmgr_resume(isc_loopmgr_t *loopmgr) {
REQUIRE(VALID_LOOPMGR(loopmgr));
REQUIRE(isc__loopmgr_tid_v != ISC_LOOPMGR_TID_UNKNOWN);
RUNTIME_CHECK(atomic_compare_exchange_strong(&loopmgr->paused,
&(bool){ true }, false));