LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ThreadSupport-PThreads.h

Go to the documentation of this file.
00001 //===-- llvm/Support/ThreadSupport-PThreads.h - PThreads support *- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines pthreads implementations of the generic threading
00011 // mechanisms.  Users should never #include this file directly!
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 // Users should never #include this file directly!  As such, no include guards
00016 // are needed.
00017 
00018 #ifndef LLVM_SUPPORT_THREADSUPPORT_H
00019 #error "Code should not #include Support/ThreadSupport/PThreads.h directly!"
00020 #endif
00021 
00022 #include <pthread.h>
00023 
00024 namespace llvm {
00025 
00026   /// Mutex - This class allows user code to protect variables shared between
00027   /// threads.  It implements a "recursive" mutex, to simplify user code.
00028   ///
00029   class Mutex {
00030     pthread_mutex_t mutex;
00031     Mutex(const Mutex &);           // DO NOT IMPLEMENT
00032     void operator=(const Mutex &);  // DO NOT IMPLEMENT
00033   public:
00034     Mutex() {
00035       pthread_mutexattr_t Attr;
00036       pthread_mutex_init(&mutex, &Attr);
00037     }
00038     ~Mutex() { pthread_mutex_destroy(&mutex); }
00039     void acquire () { pthread_mutex_lock (&mutex); }
00040     void release () { pthread_mutex_unlock (&mutex); }
00041   };
00042 } // end namespace llvm