ocf: update try-locks in env
Update try-lock's implementation to comply with new OCF trylock API Change-Id: Idc318dcac370d16312ac854d3bcf91fd7084dc65 Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447886 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
def2d0ac3e
commit
4d13903c58
34
lib/bdev/ocf/env/ocf_env.h
vendored
34
lib/bdev/ocf/env/ocf_env.h
vendored
@ -52,6 +52,7 @@
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
#include "ocf_env_list.h"
|
||||
#include "ocf/ocf_err.h"
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
@ -198,10 +199,7 @@ static inline int env_mutex_lock_interruptible(env_mutex *mutex)
|
||||
|
||||
static inline int env_mutex_trylock(env_mutex *mutex)
|
||||
{
|
||||
if (pthread_mutex_trylock(&mutex->m) == 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return pthread_mutex_trylock(&mutex->m) ? -OCF_ERR_NO_LOCK : 0;
|
||||
}
|
||||
|
||||
static inline void env_mutex_unlock(env_mutex *mutex)
|
||||
@ -211,7 +209,7 @@ static inline void env_mutex_unlock(env_mutex *mutex)
|
||||
|
||||
static inline int env_mutex_is_locked(env_mutex *mutex)
|
||||
{
|
||||
if (env_mutex_trylock(mutex)) {
|
||||
if (env_mutex_trylock(mutex) == 0) {
|
||||
env_mutex_unlock(mutex);
|
||||
return 0;
|
||||
}
|
||||
@ -275,13 +273,7 @@ static inline void env_rwsem_down_read(env_rwsem *s)
|
||||
|
||||
static inline int env_rwsem_down_read_trylock(env_rwsem *s)
|
||||
{
|
||||
int result = pthread_rwlock_tryrdlock(&s->lock);
|
||||
|
||||
if (result == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return pthread_rwlock_tryrdlock(&s->lock) ? -OCF_ERR_NO_LOCK : 0;
|
||||
}
|
||||
|
||||
static inline void env_rwsem_up_write(env_rwsem *s)
|
||||
@ -296,27 +288,17 @@ static inline void env_rwsem_down_write(env_rwsem *s)
|
||||
|
||||
static inline int env_rwsem_down_write_trylock(env_rwsem *s)
|
||||
{
|
||||
int result = pthread_rwlock_trywrlock(&s->lock);
|
||||
|
||||
if (result == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return pthread_rwlock_trywrlock(&s->lock) ? -OCF_ERR_NO_LOCK : 0;
|
||||
}
|
||||
|
||||
static inline int env_rwsem_is_locked(env_rwsem *s)
|
||||
{
|
||||
if (env_rwsem_down_write_trylock(s)) {
|
||||
env_rwsem_up_write(s);
|
||||
return 1;
|
||||
}
|
||||
if (env_rwsem_down_read_trylock(s)) {
|
||||
if (env_rwsem_down_read_trylock(s) == 0) {
|
||||
env_rwsem_up_read(s);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int env_rwsem_down_read_interruptible(env_rwsem *s)
|
||||
|
Loading…
Reference in New Issue
Block a user