From 45819211a559355093c44ad5c1d0be4dacf24e1e Mon Sep 17 00:00:00 2001 From: Michael Tuexen <tuexen@fh-muenster.de> Date: Tue, 18 Sep 2018 14:27:35 +0200 Subject: [PATCH] Cleanups and adding some assert() calls. The assert() calls clarify and ensure which thread the functions is allowed to run in. --- gtests/net/packetdrill/run.c | 2 ++ gtests/net/packetdrill/run_system_call.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gtests/net/packetdrill/run.c b/gtests/net/packetdrill/run.c index 8467bb73..8ce3ecc9 100644 --- a/gtests/net/packetdrill/run.c +++ b/gtests/net/packetdrill/run.c @@ -149,6 +149,8 @@ void state_free(struct state *state, int about_to_die) { int err; + /* This MUST NOT be called from the syscalls thread. */ + assert(!pthread_equal(pthread_self(), state->syscalls->thread)); /* We have to stop the system call thread first, since it's using * sockets that we want to close and reset. */ diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index 4a0d9396..b67d03a6 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -6933,14 +6933,13 @@ struct system_call_entry system_call_table[] = { static void invoke_system_call( struct state *state, struct event *event, struct syscall_spec *syscall) { - DEBUGP("%d: invoke call: %s\n", event->line_number, syscall->name); - char *error = NULL, *script_path = NULL; const char *name = syscall->name; struct expression_list *args = NULL; int i = 0; int result = 0; + DEBUGP("%d: invoke call: %s\n", event->line_number, syscall->name); /* Wait for the right time before firing off this event. */ wait_for_event(state); @@ -7039,6 +7038,8 @@ static void enqueue_system_call( int err; bool done = false; + /* This MUST NOT be called from the syscalls thread. */ + assert(!pthread_equal(pthread_self(), state->syscalls->thread)); /* Wait if there are back-to-back blocking system calls. */ if (await_idle_thread(state)) { asprintf(&error, "blocking system call while another blocking " @@ -7194,10 +7195,10 @@ static void *system_call_thread(void *arg) /* Check end time for the blocking system call. */ assert(state->syscalls->live_end_usecs >= 0); if (verify_time(state, - event->time_type, - syscall->end_usecs, 0, - state->syscalls->live_end_usecs, - "system call return", &error)) { + event->time_type, + syscall->end_usecs, 0, + state->syscalls->live_end_usecs, + "system call return", &error)) { die("%s:%d: %s\n", state->config->script_path, event->line_number, @@ -7241,7 +7242,7 @@ struct syscalls *syscalls_new(struct state *state) die_strerror("pthread_create", err); } - if (((err= pthread_cond_init(&syscalls->idle, NULL)) != 0) || + if (((err = pthread_cond_init(&syscalls->idle, NULL)) != 0) || ((err = pthread_cond_init(&syscalls->enqueued, NULL)) != 0) || ((err = pthread_cond_init(&syscalls->dequeued, NULL)) != 0)) { die_strerror("pthread_cond_init", err); -- GitLab