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 <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/377095
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-09-04 21:07:03 +02:00 committed by Jim Harris
parent 5ccd7974cc
commit d923a9eb2c

View File

@ -55,12 +55,6 @@ struct spdk_vhost_timed_event {
/** Semaphore used to signal that event is done. */ /** Semaphore used to signal that event is done. */
sem_t sem; 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); static int new_connection(int vid);
@ -712,41 +706,42 @@ spdk_vhost_shutdown_cb(void)
static void static void
vhost_timed_event_fn(void *arg1, void *arg2) 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) { if (ctx->cb_fn) {
ev->cb_fn(arg2); ctx->cb_fn(arg2);
} }
sem_post(&ev->sem); sem_post(&ctx->sem);
} }
void void
spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cb_fn, void *arg, spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cb_fn, void *arg,
unsigned timeout_sec, const char *errmsg) unsigned timeout_sec, const char *errmsg)
{ {
struct spdk_vhost_timed_event _ev = {0}; struct spdk_vhost_timed_event ev_ctx = {0};
struct spdk_vhost_timed_event *ev = &_ev; struct spdk_event *ev;
struct timespec timeout;
int rc; 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"); SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n");
ev->cb_fn = cb_fn; ev_ctx.cb_fn = cb_fn;
clock_gettime(CLOCK_REALTIME, &ev->timeout); clock_gettime(CLOCK_REALTIME, &timeout);
ev->timeout.tv_sec += timeout_sec; 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);
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) { if (rc != 0) {
SPDK_ERRLOG("Timout waiting for event: %s.\n", errmsg); SPDK_ERRLOG("Timout waiting for event: %s.\n", errmsg);
abort(); abort();
} }
ev->spdk_event = NULL; sem_destroy(&ev_ctx.sem);
sem_destroy(&ev->sem);
} }
void void