00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _LOG4CPP_THREADING_BOOSTTHREADS_HH
00011 #define _LOG4CPP_THREADING_BOOSTTHREADS_HH
00012
00013 #include <log4cpp/Portability.hh>
00014 #include <boost/thread/thread.hpp>
00015 #include <boost/thread/mutex.hpp>
00016 #include <boost/thread/tss.hpp>
00017 #include <cstdio>
00018 #include <string>
00019
00020 namespace log4cpp {
00021 namespace threading {
00022 static std::string getThreadId() {
00023 char buffer[14];
00024
00025 sprintf(buffer, "not available");
00026 return std::string(buffer);
00027 };
00028
00029 typedef boost::mutex Mutex;
00030 typedef boost::mutex::scoped_lock ScopedLock;
00031
00032 template<typename T> class ThreadLocalDataHolder {
00033 public:
00034 inline T* get() const {
00035 return _localData.get();
00036 };
00037
00038 inline T* operator->() const { return _localData.get(); };
00039 inline T& operator*() const { return *_localData.get(); };
00040
00041 inline T* release() {
00042 return _localData.release();
00043 };
00044
00045 inline void reset(T* p = NULL) {
00046 _localData.reset(p);
00047 };
00048
00049 private:
00050 boost::thread_specific_ptr<T> _localData;
00051 };
00052
00053 }
00054 }
00055 #endif