1*5a1d355fSStephan Aßmus // ThreadLocal.h 2*5a1d355fSStephan Aßmus 3*5a1d355fSStephan Aßmus #ifndef THREAD_LOCAL_H 4*5a1d355fSStephan Aßmus #define THREAD_LOCAL_H 5*5a1d355fSStephan Aßmus 6*5a1d355fSStephan Aßmus #include <SupportDefs.h> 7*5a1d355fSStephan Aßmus 8*5a1d355fSStephan Aßmus // ThreadLocalFreeHandler 9*5a1d355fSStephan Aßmus class ThreadLocalFreeHandler { 10*5a1d355fSStephan Aßmus public: 11*5a1d355fSStephan Aßmus ThreadLocalFreeHandler(); 12*5a1d355fSStephan Aßmus virtual ~ThreadLocalFreeHandler(); 13*5a1d355fSStephan Aßmus 14*5a1d355fSStephan Aßmus virtual void Free(void* data) = 0; 15*5a1d355fSStephan Aßmus }; 16*5a1d355fSStephan Aßmus 17*5a1d355fSStephan Aßmus // ThreadLocal 18*5a1d355fSStephan Aßmus class ThreadLocal { 19*5a1d355fSStephan Aßmus public: 20*5a1d355fSStephan Aßmus ThreadLocal( 21*5a1d355fSStephan Aßmus ThreadLocalFreeHandler* freeHandler = NULL); 22*5a1d355fSStephan Aßmus ~ThreadLocal(); 23*5a1d355fSStephan Aßmus 24*5a1d355fSStephan Aßmus status_t Set(void* data); 25*5a1d355fSStephan Aßmus void Unset(); 26*5a1d355fSStephan Aßmus void* Get() const; 27*5a1d355fSStephan Aßmus 28*5a1d355fSStephan Aßmus private: 29*5a1d355fSStephan Aßmus struct ThreadLocalMap; 30*5a1d355fSStephan Aßmus 31*5a1d355fSStephan Aßmus ThreadLocalMap* fMap; 32*5a1d355fSStephan Aßmus ThreadLocalFreeHandler* fFreeHandler; 33*5a1d355fSStephan Aßmus }; 34*5a1d355fSStephan Aßmus 35*5a1d355fSStephan Aßmus // ThreadLocalUnsetter 36*5a1d355fSStephan Aßmus class ThreadLocalUnsetter { 37*5a1d355fSStephan Aßmus public: ThreadLocalUnsetter(ThreadLocal * threadLocal)38*5a1d355fSStephan Aßmus ThreadLocalUnsetter(ThreadLocal* threadLocal) 39*5a1d355fSStephan Aßmus : fThreadLocal(threadLocal) 40*5a1d355fSStephan Aßmus { 41*5a1d355fSStephan Aßmus } 42*5a1d355fSStephan Aßmus ThreadLocalUnsetter(ThreadLocal & threadLocal)43*5a1d355fSStephan Aßmus ThreadLocalUnsetter(ThreadLocal& threadLocal) 44*5a1d355fSStephan Aßmus : fThreadLocal(&threadLocal) 45*5a1d355fSStephan Aßmus { 46*5a1d355fSStephan Aßmus } 47*5a1d355fSStephan Aßmus ~ThreadLocalUnsetter()48*5a1d355fSStephan Aßmus ~ThreadLocalUnsetter() 49*5a1d355fSStephan Aßmus { 50*5a1d355fSStephan Aßmus if (fThreadLocal) 51*5a1d355fSStephan Aßmus fThreadLocal->Unset(); 52*5a1d355fSStephan Aßmus } 53*5a1d355fSStephan Aßmus 54*5a1d355fSStephan Aßmus private: 55*5a1d355fSStephan Aßmus ThreadLocal* fThreadLocal; 56*5a1d355fSStephan Aßmus }; 57*5a1d355fSStephan Aßmus 58*5a1d355fSStephan Aßmus #endif // THREAD_LOCAL_H 59