[llvm] [llvm/Support] Make `llvm::sys::RWMutex` Lockable (PR #90667)

Alex Langford via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 14:51:41 PDT 2024


================
@@ -107,6 +108,14 @@ RWMutexImpl::unlock()
   return errorcode == 0;
 }
 
+bool RWMutexImpl::try_lock() {
+  pthread_rwlock_t *rwlock = static_cast<pthread_rwlock_t *>(data_);
+  assert(rwlock != nullptr);
+
+  int errorcode = pthread_rwlock_tryrdlock(rwlock);
----------------
bulbazord wrote:

There's an inconsistency here. `RWMutexImpl` has `shared` variants of `lock` and `unlock` that are used for reading while the plain versions of `lock` and `unlock` are for writing. I think this needs to use `pthread_rwlock_trywrlock` and then you probably want to add `RWMutexImpl::try_lock_shared()`.

https://github.com/llvm/llvm-project/pull/90667


More information about the llvm-commits mailing list