diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 201f6bced..5cfe14a54 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -109,10 +109,17 @@ void spdk_vhost_shutdown_cb(void); struct spdk_vhost_dev; /** - * Lock the global vhost mutex, which synchronizes all the vhost device accesses. + * Lock the global vhost mutex synchronizing all the vhost device accesses. */ void spdk_vhost_lock(void); +/** + * Lock the global vhost mutex synchronizing all the vhost device accesses. + * + * \return 0 if the mutex could be locked immediately, negative errno otherwise. + */ +int spdk_vhost_trylock(void); + /** * Unlock the global vhost mutex. */ diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 49c0aa9cf..55f56d5da 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1403,6 +1403,12 @@ spdk_vhost_lock(void) pthread_mutex_lock(&g_spdk_vhost_mutex); } +int +spdk_vhost_trylock(void) +{ + return -pthread_mutex_trylock(&g_spdk_vhost_mutex); +} + void spdk_vhost_unlock(void) {