tls.h 911 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef TLS_H
  2. #define TLS_H
  3. #include "fixed_types.h"
  4. class TLS
  5. {
  6. public:
  7. virtual ~TLS();
  8. virtual void* get(int thread_id = -1) = 0;
  9. virtual const void* get(int thread_id = -1) const = 0;
  10. template<class T>
  11. T& get(int thread_id = -1) { return *((T*)get(thread_id)); }
  12. template<class T>
  13. const T& get(int thread_id = -1) const { return *((const T*)get(thread_id)); }
  14. template<class T>
  15. T* getPtr(int thread_id = -1) { return (T*)get(thread_id); }
  16. template<class T>
  17. const T* getPtr(int thread_id = -1) const { return (const T*)get(thread_id); }
  18. IntPtr getInt(int thread_id = -1) const { return (intptr_t)get(thread_id); }
  19. virtual void set(void *) = 0;
  20. template<class T>
  21. void set(T *p) { set((void*)p); }
  22. void setInt(IntPtr i) { return set((void*)i); }
  23. static TLS* create();
  24. protected:
  25. TLS();
  26. };
  27. #endif // TLS_H