vhost: moved timed_event functions

In preparation to make them static

Change-Id: I086868aa88fa4f6f9f1c24b15a2e3cd0a04caab1
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/377096
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 20:48:49 +02:00 committed by Jim Harris
parent d923a9eb2c
commit 9f8efd8708

View File

@ -530,6 +530,47 @@ spdk_vhost_allocate_reactor(uint64_t cpumask)
return selected_core;
}
static void
vhost_timed_event_fn(void *arg1, void *arg2)
{
struct spdk_vhost_timed_event *ctx = arg1;
if (ctx->cb_fn) {
ctx->cb_fn(arg2);
}
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_ctx = {0};
struct spdk_event *ev;
struct timespec timeout;
int rc;
if (sem_init(&ev_ctx.sem, 0, 0) < 0)
SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n");
ev_ctx.cb_fn = cb_fn;
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec += timeout_sec;
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();
}
sem_destroy(&ev_ctx.sem);
}
static void
destroy_device(int vid)
{
@ -703,47 +744,6 @@ spdk_vhost_shutdown_cb(void)
pthread_detach(tid);
}
static void
vhost_timed_event_fn(void *arg1, void *arg2)
{
struct spdk_vhost_timed_event *ctx = arg1;
if (ctx->cb_fn) {
ctx->cb_fn(arg2);
}
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_ctx = {0};
struct spdk_event *ev;
struct timespec timeout;
int rc;
if (sem_init(&ev_ctx.sem, 0, 0) < 0)
SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n");
ev_ctx.cb_fn = cb_fn;
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec += timeout_sec;
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();
}
sem_destroy(&ev_ctx.sem);
}
void
spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{