log4tango
4.0.3
|
00001 // 00002 // DummyThreads.hh 00003 // 00004 // Copyright (C) : 2000 - 2002 00005 // LifeLine Networks BV (www.lifeline.nl). All rights reserved. 00006 // Bastiaan Bakker. All rights reserved. 00007 // 00008 // 2004,2005,2006,2007,2008,2009,2010 00009 // Synchrotron SOLEIL 00010 // L'Orme des Merisiers 00011 // Saint-Aubin - BP 48 - France 00012 // 00013 // This file is part of log4tango. 00014 // 00015 // Log4ango is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU Lesser General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 // Log4tango is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 // GNU Lesser General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU Lesser General Public License 00026 // along with Log4Tango. If not, see <http://www.gnu.org/licenses/>. 00027 00028 #ifndef _LOG4TANGO_THREADING_DUMMY_THREADS_H 00029 #define _LOG4TANGO_THREADING_DUMMY_THREADS_H 00030 00031 #include <log4tango/Portability.hh> 00032 #include <stdio.h> 00033 #include <string> 00034 00035 namespace log4tango { 00036 00037 namespace threading { 00038 00039 std::string get_thread_id (void); 00040 00041 typedef int Mutex; 00042 00043 typedef int ScopedLock; 00044 00045 #ifdef LOG4TANGO_HAS_NDC 00046 template<typename T> class ThreadLocalDataHolder 00047 { 00048 public: 00049 typedef T data_type; 00050 00051 inline ThreadLocalDataHolder () 00052 : _data(0) 00053 { 00054 //no-op 00055 }; 00056 00057 inline ~ThreadLocalDataHolder () { 00058 if (_data) { 00059 delete _data; 00060 } 00061 }; 00062 00063 inline T* get (void) const { 00064 return _data; 00065 }; 00066 00067 inline T* operator->() const { 00068 return get(); 00069 }; 00070 00071 inline T& operator*() const { 00072 return *get(); 00073 }; 00074 00075 inline T* release() { 00076 T* result = _data; 00077 _data = 0; 00078 return result; 00079 }; 00080 00081 inline void reset (T* p = 0) { 00082 if (_data) { 00083 delete _data; 00084 } 00085 _data = p; 00086 }; 00087 00088 private: 00089 T* _data; 00090 }; 00091 #endif // #ifdef LOG4TANGO_HAS_NDC 00092 00093 } // namespace threading 00094 00095 } // namespace log4tango 00096 00097 #endif // _LOG4TANGO_THREADING_DUMMY_THREADS_H