vhost: add spdk_vhost_trylock()

We'll make use of it inside the vhost device backend
code. The function itself is generic enough to be put
in the public vhost.h header rather than vhost_internal.h.

Change-Id: I60602c61d8bba665dcf9c6d27af2e910c208a7be
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448226
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-03-17 01:57:42 +01:00 committed by Jim Harris
parent 0d076e264e
commit bbfbadf59a
2 changed files with 14 additions and 1 deletions

View File

@ -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.
*/

View File

@ -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)
{