15#include "llvm/Config/config.h"
17#if defined(LLVM_USE_RW_MUTEX_IMPL)
21#if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
24RWMutexImpl::RWMutexImpl() =
default;
25RWMutexImpl::~RWMutexImpl() =
default;
27bool RWMutexImpl::lock_shared() {
return true; }
28bool RWMutexImpl::unlock_shared() {
return true; }
29bool RWMutexImpl::try_lock_shared() {
return true; }
30bool RWMutexImpl::lock() {
return true; }
31bool RWMutexImpl::unlock() {
return true; }
32bool RWMutexImpl::try_lock() {
return true; }
36#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_RWLOCK_INIT)
43RWMutexImpl::RWMutexImpl()
46 pthread_rwlock_t* rwlock =
47 static_cast<pthread_rwlock_t*
>(
safe_malloc(
sizeof(pthread_rwlock_t)));
51 bzero(rwlock,
sizeof(pthread_rwlock_t));
55 int errorcode = pthread_rwlock_init(rwlock,
nullptr);
64RWMutexImpl::~RWMutexImpl()
66 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
68 pthread_rwlock_destroy(rwlock);
73RWMutexImpl::lock_shared()
75 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
78 int errorcode = pthread_rwlock_rdlock(rwlock);
79 return errorcode == 0;
83RWMutexImpl::unlock_shared()
85 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
88 int errorcode = pthread_rwlock_unlock(rwlock);
89 return errorcode == 0;
92bool RWMutexImpl::try_lock_shared() {
93 pthread_rwlock_t *rwlock =
static_cast<pthread_rwlock_t *
>(data_);
96 int errorcode = pthread_rwlock_tryrdlock(rwlock);
97 return errorcode == 0;
103 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
104 assert(rwlock !=
nullptr);
106 int errorcode = pthread_rwlock_wrlock(rwlock);
107 return errorcode == 0;
113 pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*
>(data_);
114 assert(rwlock !=
nullptr);
116 int errorcode = pthread_rwlock_unlock(rwlock);
117 return errorcode == 0;
120bool RWMutexImpl::try_lock() {
121 pthread_rwlock_t *rwlock =
static_cast<pthread_rwlock_t *
>(data_);
122 assert(rwlock !=
nullptr);
124 int errorcode = pthread_rwlock_trywrlock(rwlock);
125 return errorcode == 0;
130RWMutexImpl::RWMutexImpl() : data_(new MutexImpl(
false)) { }
132RWMutexImpl::~RWMutexImpl() {
133 delete static_cast<MutexImpl *
>(data_);
136bool RWMutexImpl::lock_shared() {
137 return static_cast<MutexImpl *
>(data_)->
acquire();
140bool RWMutexImpl::unlock_shared() {
141 return static_cast<MutexImpl *
>(data_)->
release();
144bool RWMutexImpl::try_lock_shared() {
145 return static_cast<MutexImpl *
>(data_)->tryacquire();
148bool RWMutexImpl::lock() {
149 return static_cast<MutexImpl *
>(data_)->
acquire();
152bool RWMutexImpl::unlock() {
153 return static_cast<MutexImpl *
>(data_)->
release();
156bool RWMutexImpl::try_lock() {
157 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)