vhost: factor out semaphore usage
We'll start using the same code in even more places soon, so put in a function. Change-Id: Iee2e091009b14e9d8b56ec8f0d4a86094f7c9727 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467229 Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
2072d16e94
commit
81883ec5a7
@ -902,6 +902,28 @@ _get_current_poll_group(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wait_for_semaphore(int timeout_sec, const char *errmsg)
|
||||||
|
{
|
||||||
|
struct timespec timeout;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &timeout);
|
||||||
|
timeout.tv_sec += timeout_sec;
|
||||||
|
rc = sem_timedwait(&g_dpdk_sem, &timeout);
|
||||||
|
if (rc != 0) {
|
||||||
|
SPDK_ERRLOG("Timeout waiting for event: %s.\n", errmsg);
|
||||||
|
sem_wait(&g_dpdk_sem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vhost_session_cb_done(int rc)
|
||||||
|
{
|
||||||
|
g_dpdk_response = rc;
|
||||||
|
sem_post(&g_dpdk_sem);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
vhost_session_start_done(struct spdk_vhost_session *vsession, int response)
|
vhost_session_start_done(struct spdk_vhost_session *vsession, int response)
|
||||||
{
|
{
|
||||||
@ -916,8 +938,7 @@ vhost_session_start_done(struct spdk_vhost_session *vsession, int response)
|
|||||||
vsession->vdev->active_session_num++;
|
vsession->vdev->active_session_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_dpdk_response = response;
|
vhost_session_cb_done(response);
|
||||||
sem_post(&g_dpdk_sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -934,8 +955,7 @@ vhost_session_stop_done(struct spdk_vhost_session *vsession, int response)
|
|||||||
vsession->vdev->active_session_num--;
|
vsession->vdev->active_session_num--;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_dpdk_response = response;
|
vhost_session_cb_done(response);
|
||||||
sem_post(&g_dpdk_sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -961,26 +981,17 @@ vhost_session_send_event(struct vhost_poll_group *pg,
|
|||||||
const char *errmsg)
|
const char *errmsg)
|
||||||
{
|
{
|
||||||
struct vhost_session_fn_ctx ev_ctx = {0};
|
struct vhost_session_fn_ctx ev_ctx = {0};
|
||||||
struct timespec timeout;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
ev_ctx.vdev = vsession->vdev;
|
ev_ctx.vdev = vsession->vdev;
|
||||||
ev_ctx.vsession_id = vsession->id;
|
ev_ctx.vsession_id = vsession->id;
|
||||||
ev_ctx.cb_fn = cb_fn;
|
ev_ctx.cb_fn = cb_fn;
|
||||||
|
|
||||||
spdk_thread_send_msg(pg->thread, vhost_event_cb, &ev_ctx);
|
spdk_thread_send_msg(pg->thread, vhost_event_cb, &ev_ctx);
|
||||||
|
|
||||||
pthread_mutex_unlock(&g_vhost_mutex);
|
pthread_mutex_unlock(&g_vhost_mutex);
|
||||||
|
wait_for_semaphore(timeout_sec, errmsg);
|
||||||
clock_gettime(CLOCK_REALTIME, &timeout);
|
|
||||||
timeout.tv_sec += timeout_sec;
|
|
||||||
|
|
||||||
rc = sem_timedwait(&g_dpdk_sem, &timeout);
|
|
||||||
if (rc != 0) {
|
|
||||||
SPDK_ERRLOG("Timeout waiting for event: %s.\n", errmsg);
|
|
||||||
sem_wait(&g_dpdk_sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_lock(&g_vhost_mutex);
|
pthread_mutex_lock(&g_vhost_mutex);
|
||||||
|
|
||||||
return g_dpdk_response;
|
return g_dpdk_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user