Reduce the number of client tasks and bind them to netmgr queues

Since a client object is bound to a netmgr handle, each client
will always be processed by the same netmgr worker, so we can
simplify the code by binding client->task to the same thread as
the client. Since ns__client_request() now runs in the same event
loop as client->task events, is no longer necessary to pause the
task manager before launching them.

Also removed some functions in isc_task that were not used.
This commit is contained in:
Ondřej Surý
2021-05-18 19:44:31 +02:00
parent c07f8c5a43
commit 0be7ea78be
5 changed files with 16 additions and 253 deletions

View File

@@ -48,7 +48,7 @@ static isc_condition_t cv;
atomic_int_fast32_t counter;
static int active[10];
static atomic_bool done, done2;
static atomic_bool done;
static int
_setup(void **state) {
@@ -417,83 +417,6 @@ privilege_drop(void **state) {
assert_null(task2);
}
static void
sleep_cb(isc_task_t *task, isc_event_t *event) {
UNUSED(task);
int p = *(int *)event->ev_arg;
if (p == 1) {
/*
* Signal the main thread that we're running, so that
* it can trigger the race.
*/
LOCK(&lock);
atomic_store(&done2, true);
SIGNAL(&cv);
UNLOCK(&lock);
/*
* Wait for the operations in the main thread to be finished.
*/
LOCK(&lock);
while (!atomic_load(&done)) {
WAIT(&cv, &lock);
}
UNLOCK(&lock);
} else {
/*
* Wait for the operations in the main thread to be finished.
*/
LOCK(&lock);
atomic_store(&done2, true);
SIGNAL(&cv);
UNLOCK(&lock);
}
isc_event_free(&event);
}
static void
pause_unpause(void **state) {
isc_result_t result;
isc_task_t *task = NULL;
isc_event_t *event1, *event2 = NULL;
UNUSED(state);
atomic_store(&done, false);
atomic_store(&done2, false);
result = isc_task_create(taskmgr, 0, &task);
assert_int_equal(result, ISC_R_SUCCESS);
event1 = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST,
sleep_cb, &(int){ 1 }, sizeof(isc_event_t));
assert_non_null(event1);
event2 = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST,
sleep_cb, &(int){ 2 }, sizeof(isc_event_t));
assert_non_null(event2);
isc_task_send(task, &event1);
isc_task_send(task, &event2);
/* Wait for event1 to be running */
LOCK(&lock);
while (!atomic_load(&done2)) {
WAIT(&cv, &lock);
}
UNLOCK(&lock);
/* Pause-unpause-detach is what causes the race */
isc_task_pause(task);
isc_task_unpause(task);
isc_task_detach(&task);
/* Signal event1 to finish */
LOCK(&lock);
atomic_store(&done2, false);
atomic_store(&done, true);
SIGNAL(&cv);
UNLOCK(&lock);
/* Wait for event2 to finish */
LOCK(&lock);
while (!atomic_load(&done2)) {
WAIT(&cv, &lock);
}
UNLOCK(&lock);
}
/*
* Basic task functions:
*/
@@ -1536,8 +1459,6 @@ main(int argc, char **argv) {
cmocka_unit_test_setup_teardown(all_events, _setup, _teardown),
cmocka_unit_test_setup_teardown(basic, _setup2, _teardown),
cmocka_unit_test_setup_teardown(create_task, _setup, _teardown),
cmocka_unit_test_setup_teardown(pause_unpause, _setup,
_teardown),
cmocka_unit_test_setup_teardown(post_shutdown, _setup2,
_teardown),
cmocka_unit_test_setup_teardown(privilege_drop, _setup,