mirror of
https://github.com/torvalds/linux.git
synced 2026-11-27 17:02:17 +00:00
Mutex error check will capture trying to take the lock recursively and other problems that rwlock won't. At the expense of concurrency, adda debug mode that uses a mutex in place of a rwsem. Signed-off-by: Ian Rogers <[email protected]> Cc: K Prateek Nayak <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Sandipan Das <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: German Gomez <[email protected]> Cc: James Clark <[email protected]> Cc: Nick Terrell <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Changbin Du <[email protected]> Cc: liuwenyu <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Song Liu <[email protected]> Cc: Leo Yan <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Kan Liang <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Yanteng Si <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Paolo Bonzini <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
68 lines
1.1 KiB
C
68 lines
1.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "util.h"
|
|
#include "rwsem.h"
|
|
|
|
#if RWS_ERRORCHECK
|
|
#include "mutex.h"
|
|
#endif
|
|
|
|
int init_rwsem(struct rw_semaphore *sem)
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_init(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return pthread_rwlock_init(&sem->lock, NULL);
|
|
#endif
|
|
}
|
|
|
|
int exit_rwsem(struct rw_semaphore *sem)
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_destroy(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return pthread_rwlock_destroy(&sem->lock);
|
|
#endif
|
|
}
|
|
|
|
int down_read(struct rw_semaphore *sem)
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_lock(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);
|
|
#endif
|
|
}
|
|
|
|
int up_read(struct rw_semaphore *sem)
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_unlock(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
|
|
#endif
|
|
}
|
|
|
|
int down_write(struct rw_semaphore *sem)
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_lock(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);
|
|
#endif
|
|
}
|
|
|
|
int up_write(struct rw_semaphore *sem)
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_unlock(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
|
|
#endif
|
|
}
|