Add more doxygen comments for llvm::ThreadLocal.
[oota-llvm.git] / include / llvm / System / ThreadLocal.h
1 //===- llvm/System/ThreadLocal.h - Thread Local Data ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the llvm::sys::ThreadLocal class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_THREAD_LOCAL_H
15 #define LLVM_SYSTEM_THREAD_LOCAL_H
16
17 #include "llvm/System/Threading.h"
18 #include <cassert>
19
20 namespace llvm {
21   namespace sys {
22     // ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
23     // YOU SHOULD NEVER USE THIS DIRECTLY.
24     class ThreadLocalImpl {
25       void* data;
26     public:
27       ThreadLocalImpl();
28       virtual ~ThreadLocalImpl();
29       void setInstance(const void* d);
30       const void* getInstance();
31     };
32     
33     /// ThreadLocal - A class used to abstract thread-local storage.  It holds,
34     /// for each thread, a pointer a single object of type T.
35     template<class T>
36     class ThreadLocal : public ThreadLocalImpl {
37     public:
38       ThreadLocal() : ThreadLocalImpl() { }
39       
40       /// get - Fetches a pointer to the object associated with the current
41       /// thread.  If no object has yet been associated, it returns NULL;
42       T* get() { return static_cast<T*>(getInstance()); }
43       
44       // set - Associates a pointer to an object with the current thread.
45       void set(T* d) { setInstance(d); }
46     };
47   }
48 }
49
50 #endif