DummyThreads.hh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * DummyThreads.hh
  3. *
  4. * Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
  5. * Copyright 2002, Bastiaan Bakker. All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #ifndef _LOG4CPP_THREADING_DUMMYTHREADS_HH
  10. #define _LOG4CPP_THREADING_DUMMYTHREADS_HH
  11. #include <log4cpp/Portability.hh>
  12. #include <stdio.h>
  13. #include <string>
  14. LOG4CPP_NS_BEGIN
  15. namespace threading {
  16. std::string getThreadId();
  17. /**
  18. Dummy type 'int' for Mutex. Yes, this adds a bit of overhead in
  19. the for of extra memory, but unfortunately 'void' is illegal.
  20. **/
  21. typedef int Mutex;
  22. /**
  23. Dummy type 'int' defintion of ScopedLock;
  24. **/
  25. typedef int ScopedLock;
  26. template<typename T> class ThreadLocalDataHolder {
  27. public:
  28. typedef T data_type;
  29. inline ThreadLocalDataHolder() {};
  30. inline ~ThreadLocalDataHolder() {
  31. if (_data)
  32. delete _data;
  33. };
  34. inline T* get() const {
  35. return _data;
  36. };
  37. inline T* operator->() const { return get(); };
  38. inline T& operator*() const { return *get(); };
  39. inline T* release() {
  40. T* result = _data;
  41. _data = NULL;
  42. return result;
  43. };
  44. inline void reset(T* p = NULL) {
  45. if (_data)
  46. delete _data;
  47. _data = p;
  48. };
  49. private:
  50. T* _data;
  51. };
  52. }
  53. LOG4CPP_NS_END
  54. #endif