mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Add annotations used by clang's -Wthread-safety. Fix dsos compilation errors caused by a lock of annotations. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Bill Wendling <morbo@google.com> Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com> Cc: Fei Lang <langfei@huawei.com> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Justin Stitt <justinstitt@google.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Link: https://lore.kernel.org/r/20250519224645.1810891-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
71 lines
1.2 KiB
C
71 lines
1.2 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)
|
|
NO_THREAD_SAFETY_ANALYSIS
|
|
{
|
|
#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)
|
|
NO_THREAD_SAFETY_ANALYSIS
|
|
{
|
|
#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)
|
|
NO_THREAD_SAFETY_ANALYSIS
|
|
{
|
|
#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)
|
|
NO_THREAD_SAFETY_ANALYSIS
|
|
{
|
|
#if RWS_ERRORCHECK
|
|
mutex_unlock(&sem->mtx);
|
|
return 0;
|
|
#else
|
|
return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
|
|
#endif
|
|
}
|