#ifndef __MARSDEBUGTOOLS_H__ #define __MARSDEBUGTOOLS_H__ #include #include #include #include namespace mars { enum ThreadingModel { ThrMdl_Main, ThrMdl_Single, ThrMdl_Any }; extern class ThreadingModelManager { public: ThreadingModelManager(); void registerMainThread (); size_t registerThread (const char * szFuncName, const void * pThis); size_t deregisterThread (const char * szFuncName, const void * pThis); bool checkMainThread (const char * szFuncName); private: typedef std::set< boost::thread::id > ThreadIDSet; typedef std::map< std::string, ThreadIDSet > ThreadConcurrencyMap; typedef std::map< std::pair< std::string, const void * >, size_t > ThreadReferenceCountMap; mutable boost::mutex _mtxMutex; ThreadConcurrencyMap _mapThreadTracker; ThreadReferenceCountMap _mapRefCounter; boost::thread::id _idMainThread; bool _bMainThreadSet; } gtmm_ThreadingModelManager; class ThreadingModelMonitor { public: ThreadingModelMonitor (const char * szFuncName, const void * oInst, const ThreadingModel entmThreadingModel); ~ThreadingModelMonitor(); private: ThreadingModel _entmThreadingModel; boost::thread::id _idThread; const char * _szFuncName; const void * _pInst; }; } #ifdef _DEBUG #define assert_threadmodel(entmThreadingModel) mars::ThreadingModelMonitor tmm(__FUNCTION__, this, entmThreadingModel) #define register_mainthread() mars::gtmm_ThreadingModelManager.registerMainThread() #else #define assert_threadmodel(x) #define register_mainthread() #endif #endif