diff options
author | Owen Anderson <resistor@mac.com> | 2009-06-17 20:34:43 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-06-17 20:34:43 +0000 |
commit | dd561e153971c058138eed7a8212a26d011bbbef (patch) | |
tree | b4caf499604fdd14fb938a8af511264489d0a191 /include/llvm/System/RWMutex.h | |
parent | 31c36f02f26def914727a521e7ca5fad450920ca (diff) | |
download | llvm-dd561e153971c058138eed7a8212a26d011bbbef.tar.gz llvm-dd561e153971c058138eed7a8212a26d011bbbef.tar.bz2 llvm-dd561e153971c058138eed7a8212a26d011bbbef.tar.xz |
Add an RAII ScopedWriter, which allows one to acquire a writer lock for the duration of a scope. Simplify a lot of uses of
writer locks in Constants.cpp by using it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73630 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/System/RWMutex.h')
-rw-r--r-- | include/llvm/System/RWMutex.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/System/RWMutex.h b/include/llvm/System/RWMutex.h index 2b466f20b4..6ac7aa3c2b 100644 --- a/include/llvm/System/RWMutex.h +++ b/include/llvm/System/RWMutex.h @@ -78,6 +78,20 @@ namespace llvm void operator=(const RWMutex &); /// @} }; + + /// ScopedWriter - RAII acquisition of a writer lock + struct ScopedWriter { + RWMutex* mutex; + + explicit ScopedWriter(RWMutex* m) { + mutex = m; + mutex->writer_acquire(); + } + + ~ScopedWriter() { + mutex->writer_release(); + } + }; } } |