Changes For Bug 352
[oota-llvm.git] / include / llvm / Support / ThreadSupport-PThreads.h
1 //===-- llvm/Support/ThreadSupport-PThreads.h - PThreads support *- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines pthreads implementations of the generic threading
11 // mechanisms.  Users should never #include this file directly!
12 //
13 //===----------------------------------------------------------------------===//
14
15 // Users should never #include this file directly!  As such, no include guards
16 // are needed.
17
18 #ifndef LLVM_SUPPORT_THREADSUPPORT_H
19 #error "Code should not #include Support/ThreadSupport/PThreads.h directly!"
20 #endif
21
22 #include <pthread.h>
23
24 namespace llvm {
25
26   /// Mutex - This class allows user code to protect variables shared between
27   /// threads.  It implements a "recursive" mutex, to simplify user code.
28   ///
29   class Mutex {
30     pthread_mutex_t mutex;
31     Mutex(const Mutex &);           // DO NOT IMPLEMENT
32     void operator=(const Mutex &);  // DO NOT IMPLEMENT
33   public:
34     Mutex() {
35       pthread_mutexattr_t Attr;
36       pthread_mutex_init(&mutex, &Attr);
37     }
38     ~Mutex() { pthread_mutex_destroy(&mutex); }
39     void acquire () { pthread_mutex_lock (&mutex); }
40     void release () { pthread_mutex_unlock (&mutex); }
41   };
42 } // end namespace llvm