[llvm-commits] CVS: llvm/include/llvm/Support/ThreadSupport-PThreads.h
Chris Lattner
lattner at cs.uiuc.edu
Sun Feb 27 11:07:52 PST 2005
Changes in directory llvm/include/llvm/Support:
ThreadSupport-PThreads.h updated: 1.3 -> 1.4
---
Log message:
Fix this to create a recursive mutex. Patch by Evan Jones!
---
Diffs of the changes: (+27 -4)
ThreadSupport-PThreads.h | 31 +++++++++++++++++++++++++++----
1 files changed, 27 insertions(+), 4 deletions(-)
Index: llvm/include/llvm/Support/ThreadSupport-PThreads.h
diff -u llvm/include/llvm/Support/ThreadSupport-PThreads.h:1.3 llvm/include/llvm/Support/ThreadSupport-PThreads.h:1.4
--- llvm/include/llvm/Support/ThreadSupport-PThreads.h:1.3 Wed Sep 1 17:55:35 2004
+++ llvm/include/llvm/Support/ThreadSupport-PThreads.h Sun Feb 27 13:07:36 2005
@@ -32,11 +32,34 @@
void operator=(const Mutex &); // DO NOT IMPLEMENT
public:
Mutex() {
+ // Initialize the mutex as a recursive mutex
pthread_mutexattr_t Attr;
- pthread_mutex_init(&mutex, &Attr);
+ int errorcode = pthread_mutexattr_init(&Attr);
+ assert(errorcode == 0);
+
+ errorcode = pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE);
+ assert(errorcode == 0);
+
+ errorcode = pthread_mutex_init(&mutex, &Attr);
+ assert(errorcode == 0);
+
+ errorcode = pthread_mutexattr_destroy(&Attr);
+ assert(errorcode == 0);
+ }
+
+ ~Mutex() {
+ int errorcode = pthread_mutex_destroy(&mutex);
+ assert(errorcode == 0);
+ }
+
+ void acquire () {
+ int errorcode = pthread_mutex_lock(&mutex);
+ assert(errorcode == 0);
+ }
+
+ void release () {
+ int errorcode = pthread_mutex_unlock(&mutex);
+ assert(errorcode == 0);
}
- ~Mutex() { pthread_mutex_destroy(&mutex); }
- void acquire () { pthread_mutex_lock (&mutex); }
- void release () { pthread_mutex_unlock (&mutex); }
};
} // end namespace llvm
More information about the llvm-commits
mailing list