From: <ag...@us...> - 2008-08-04 04:23:19
|
Revision: 80 http://zoolib.svn.sourceforge.net/zoolib/?rev=80&view=rev Author: agreen Date: 2008-08-04 04:23:27 +0000 (Mon, 04 Aug 2008) Log Message: ----------- I've broken the ZThread InitHelper stuff out into a separate file (ZThreadMain), which only has to be incorporated into a build if deadlock detection is being done, or you're building for Windows. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZThread.cpp trunk/zoolib/source/cxx/zoolib/ZThread.h Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp trunk/zoolib/source/cxx/zoolib/ZThreadMain.h Modified: trunk/zoolib/source/cxx/zoolib/ZThread.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.cpp 2008-08-04 04:18:38 UTC (rev 79) +++ trunk/zoolib/source/cxx/zoolib/ZThread.cpp 2008-08-04 04:23:27 UTC (rev 80) @@ -164,38 +164,6 @@ ZAssertStop(kDebug_Thread, priorValue == 1); } -// ================================================================================================= -#pragma mark - -#pragma mark * ZThread Initialization/Tear Down - -namespace ZANONYMOUS { - -class MainThread : public ZThread - { -public: - MainThread() : ZThread((struct ZooLib::Dummy*)(0)){} - virtual void Run() {} - }; - -} // anonymous namespace - -static int sInitCount; - -ZThread::InitHelper::InitHelper() - { - if (sInitCount++ != 0) - return; - - new MainThread; - } - -ZThread::InitHelper::~InitHelper() - { - if (--sInitCount != 0) - return; - delete sMainThread; - } - // ================================================== #pragma mark - #pragma mark * ZThread ctor/dtor @@ -234,7 +202,9 @@ ZThread::ZThread(const char* iName) { - ZAssertStop(kDebug_Thread, sMainThread); + if (ZCONFIG_Thread_DeadlockDetect || ZCONFIG(API_Thread, Win32)) + ZAssertStop(kDebug_Thread, sMainThread); + fThreadID = kThreadID_None; fStarted = false; fName = iName; Modified: trunk/zoolib/source/cxx/zoolib/ZThread.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.h 2008-08-04 04:18:38 UTC (rev 79) +++ trunk/zoolib/source/cxx/zoolib/ZThread.h 2008-08-04 04:23:27 UTC (rev 80) @@ -60,7 +60,7 @@ // Do we want deadlock detection to be active? #ifndef ZCONFIG_Thread_DeadlockDetect -# if ZCONFIG_Debug >= 1 +# if ZCONFIG_Debug >= 2 # define ZCONFIG_Thread_DeadlockDetect 1 # else # define ZCONFIG_Thread_DeadlockDetect 0 @@ -90,6 +90,10 @@ # define ZCONFIG_Thread_Preemptive 1 #endif +#if ZCONFIG_Thread_DeadlockDetect || ZCONFIG(API_Thread, Win32) +# include "zoolib/ZThreadMain.h" +#endif + // ================================================== // A macro that has proven to be useful. #define ZAssertLocked(a, b) ZAssertStop(a, (b).IsLocked()) @@ -157,7 +161,7 @@ class ZThread : ZooLib::NonCopyable { protected: - // This protected constructor is used indirectly by ZThread::InitHelper. + // This protected constructor is used indirectly by ZThreadMainInitHelper. ZThread(struct Dummy*); // Our destructor is protected, so even with its pointer semantics it's illegal to @@ -300,24 +304,6 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZThread::InitHelper - -class ZThread::InitHelper - { -public: - InitHelper(); - ~InitHelper(); - }; - -// This static is what makes auto-initialization work. Every file that (transitively) includes ZThread.h will -// get their own instance of a ZThread::InitHelper, whose constructor creates the main thread object and -// whose destructor deletes it. This ensures that ZThread is initialized at static construction time -// and is usable regardless of the link order. - -static ZThread::InitHelper sZThread_InitHelper; - -// ================================================================================================= -#pragma mark - #pragma mark * ZThread::Ex_Disposed class ZThread::Ex_Disposed : public std::runtime_error Added: trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp 2008-08-04 04:23:27 UTC (rev 80) @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZThreadMain.h" + +// ================================================================================================= +#pragma mark - +#pragma mark * ZThreadMain + +namespace ZANONYMOUS { + +class MainThread : public ZThread + { +public: + MainThread() : ZThread((struct ZooLib::Dummy*)(0)){} + virtual void Run() {} + }; + +} // anonymous namespace + +static int sInitCount; + +ZThread::InitHelper::InitHelper() + { + if (sInitCount++ != 0) + return; + + new MainThread; + } + +ZThread::InitHelper::~InitHelper() + { + if (--sInitCount != 0) + return; + delete sMainThread; + } Added: trunk/zoolib/source/cxx/zoolib/ZThreadMain.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadMain.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadMain.h 2008-08-04 04:23:27 UTC (rev 80) @@ -0,0 +1,49 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZThreadMain__ +#define __ZThreadMain__ 1 +#include "zconfig.h" + +#include "zoolib/ZThread.h" + +// ================================================================================================= +#pragma mark - +#pragma mark * ZThreadMain + +namespace ZooLib { + +class ZThreadMainInitHelper + { +public: + ZThreadMainInitHelper(); + ~ZThreadMainInitHelper(); + }; + +// This static is what makes auto-initialization work. Every file that (transitively) includes ZThread.h will +// get their own instance of a ZThread::InitHelper, whose constructor creates the main thread object and +// whose destructor deletes it. This ensures that ZThread is initialized at static construction time +// and is usable regardless of the link order. + +static ZThreadMainInitHelper sZThread_InitHelper; + +} // namespace ZooLib + +#endif // __ZThreadMain__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |