From d923a9eb2cd85f70c1452d5db7f0f826c7492aba Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Mon, 4 Sep 2017 21:07:03 +0200 Subject: [PATCH] vhost: simplified timed event code Removed leftover code. spdk_vhost_timed_event struct has been stripped from spdk_event and timeout fields. The first one was not required since vhost_timed_events are not reusable anymore. The latter has been removed to prepare vhost_timed_event struct to be expanded to generic - also non-timing out - vhost_event struct. Change-Id: Ifd22f59b2748752f2776700676f07e70b45957ed Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/377095 Tested-by: SPDK Automated Test System Reviewed-by: Pawel Wodkowski Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- lib/vhost/vhost.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 13833dfa7..62ab41760 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -55,12 +55,6 @@ struct spdk_vhost_timed_event { /** Semaphore used to signal that event is done. */ sem_t sem; - - /** Timout specified during initialization. */ - struct timespec timeout; - - /** Event object that can be passed to *spdk_event_call()*. */ - struct spdk_event *spdk_event; }; static int new_connection(int vid); @@ -712,41 +706,42 @@ spdk_vhost_shutdown_cb(void) static void vhost_timed_event_fn(void *arg1, void *arg2) { - struct spdk_vhost_timed_event *ev = arg1; + struct spdk_vhost_timed_event *ctx = arg1; - if (ev->cb_fn) { - ev->cb_fn(arg2); + if (ctx->cb_fn) { + ctx->cb_fn(arg2); } - sem_post(&ev->sem); + sem_post(&ctx->sem); } void spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cb_fn, void *arg, unsigned timeout_sec, const char *errmsg) { - struct spdk_vhost_timed_event _ev = {0}; - struct spdk_vhost_timed_event *ev = &_ev; + struct spdk_vhost_timed_event ev_ctx = {0}; + struct spdk_event *ev; + struct timespec timeout; int rc; - if (sem_init(&ev->sem, 0, 0) < 0) + if (sem_init(&ev_ctx.sem, 0, 0) < 0) SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n"); - ev->cb_fn = cb_fn; - clock_gettime(CLOCK_REALTIME, &ev->timeout); - ev->timeout.tv_sec += timeout_sec; - ev->spdk_event = spdk_event_allocate(lcore, vhost_timed_event_fn, ev, arg); - assert(ev->spdk_event); - spdk_event_call(ev->spdk_event); + ev_ctx.cb_fn = cb_fn; + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec += timeout_sec; - rc = sem_timedwait(&ev->sem, &ev->timeout); + ev = spdk_event_allocate(lcore, vhost_timed_event_fn, &ev_ctx, arg); + assert(ev); + spdk_event_call(ev); + + rc = sem_timedwait(&ev_ctx.sem, &timeout); if (rc != 0) { SPDK_ERRLOG("Timout waiting for event: %s.\n", errmsg); abort(); } - ev->spdk_event = NULL; - sem_destroy(&ev->sem); + sem_destroy(&ev_ctx.sem); } void