14#include "llvm/Config/config.h"
15#include "llvm/Config/llvm-config.h"
18#if defined(LLVM_USE_RW_MUTEX_IMPL)
22#if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
25RWMutexImpl::RWMutexImpl() =
default;
26RWMutexImpl::~RWMutexImpl() =
default;
28bool RWMutexImpl::lock_shared() {
return true; }
29bool RWMutexImpl::unlock_shared() {
return true; }
30bool RWMutexImpl::try_lock_shared() {
return true; }
31bool RWMutexImpl::lock() {
return true; }
32bool RWMutexImpl::unlock() {
return true; }
33bool RWMutexImpl::try_lock() {
return true; }
37#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_RWLOCK_INIT)
44RWMutexImpl::RWMutexImpl()
47 pthread_rwlock_t* rwlock =
48 static_cast<pthread_rwlock_t*
>(
safe_malloc(
sizeof(pthread_rwlock_t)));
52 bzero(rwlock,
sizeof(pthread_rwlock_t));
56 int errorcode = pthread_rwlock_init(rwlock,
nullptr);
65RWMutexImpl::~RWMutexImpl()
67 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
69 pthread_rwlock_destroy(rwlock);
74RWMutexImpl::lock_shared()
76 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
79 int errorcode = pthread_rwlock_rdlock(rwlock);
80 return errorcode == 0;
84RWMutexImpl::unlock_shared()
86 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
89 int errorcode = pthread_rwlock_unlock(rwlock);
90 return errorcode == 0;
93bool RWMutexImpl::try_lock_shared() {
94 pthread_rwlock_t *rwlock =
static_cast<pthread_rwlock_t *
>(data_);
97 int errorcode = pthread_rwlock_tryrdlock(rwlock);
98 return errorcode == 0;
104 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
105 assert(rwlock !=
nullptr);
107 int errorcode = pthread_rwlock_wrlock(rwlock);
108 return errorcode == 0;
114 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
115 assert(rwlock !=
nullptr);
117 int errorcode = pthread_rwlock_unlock(rwlock);
118 return errorcode == 0;
121bool RWMutexImpl::try_lock() {
122 pthread_rwlock_t *rwlock =
static_cast<pthread_rwlock_t *
>(data_);
123 assert(rwlock !=
nullptr);
125 int errorcode = pthread_rwlock_trywrlock(rwlock);
126 return errorcode == 0;
131RWMutexImpl::RWMutexImpl() : data_(new MutexImpl(
false)) { }
133RWMutexImpl::~RWMutexImpl() {
134 delete static_cast<MutexImpl *
>(data_);
137bool RWMutexImpl::lock_shared() {
138 return static_cast<MutexImpl *
>(data_)->
acquire();
141bool RWMutexImpl::unlock_shared() {
142 return static_cast<MutexImpl *
>(data_)->
release();
145bool RWMutexImpl::try_lock_shared() {
146 return static_cast<MutexImpl *
>(data_)->tryacquire();
149bool RWMutexImpl::lock() {
150 return static_cast<MutexImpl *
>(data_)->
acquire();
153bool RWMutexImpl::unlock() {
154 return static_cast<MutexImpl *
>(data_)->
release();
157bool RWMutexImpl::try_lock() {
158 return static_cast<MutexImpl *
>(data_)->tryacquire();
This file defines the BumpPtrAllocator interface.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)