[80a6a52] | 1 | #ifndef __MARSDEBUGTOOLS_H__
|
---|
| 2 | #define __MARSDEBUGTOOLS_H__
|
---|
| 3 |
|
---|
| 4 | #include <boost/thread.hpp>
|
---|
| 5 | #include <map>
|
---|
| 6 | #include <set>
|
---|
| 7 | #include <string>
|
---|
| 8 |
|
---|
| 9 | namespace mars
|
---|
| 10 | {
|
---|
| 11 | enum ThreadingModel
|
---|
| 12 | {
|
---|
| 13 | ThrMdl_Main,
|
---|
| 14 | ThrMdl_Single,
|
---|
| 15 | ThrMdl_Any
|
---|
| 16 | };
|
---|
| 17 |
|
---|
| 18 | extern class ThreadingModelManager
|
---|
| 19 | {
|
---|
| 20 | public:
|
---|
| 21 | ThreadingModelManager();
|
---|
| 22 |
|
---|
| 23 | void registerMainThread ();
|
---|
| 24 | size_t registerThread (const char * szFuncName, const void * pThis);
|
---|
| 25 | size_t deregisterThread (const char * szFuncName, const void * pThis);
|
---|
| 26 | bool checkMainThread (const char * szFuncName);
|
---|
| 27 |
|
---|
| 28 | private:
|
---|
| 29 | typedef std::set< boost::thread::id > ThreadIDSet;
|
---|
| 30 | typedef std::map< std::string, ThreadIDSet > ThreadConcurrencyMap;
|
---|
| 31 | typedef std::map< std::pair< std::string, const void * >, size_t > ThreadReferenceCountMap;
|
---|
| 32 |
|
---|
| 33 | mutable boost::mutex _mtxMutex;
|
---|
| 34 | ThreadConcurrencyMap _mapThreadTracker;
|
---|
| 35 | ThreadReferenceCountMap _mapRefCounter;
|
---|
| 36 | boost::thread::id _idMainThread;
|
---|
| 37 | bool _bMainThreadSet;
|
---|
| 38 | } gtmm_ThreadingModelManager;
|
---|
| 39 |
|
---|
| 40 | class ThreadingModelMonitor
|
---|
| 41 | {
|
---|
| 42 | public:
|
---|
| 43 | ThreadingModelMonitor (const char * szFuncName, const void * oInst, const ThreadingModel entmThreadingModel);
|
---|
| 44 | ~ThreadingModelMonitor();
|
---|
| 45 |
|
---|
| 46 | private:
|
---|
| 47 | ThreadingModel _entmThreadingModel;
|
---|
| 48 | boost::thread::id _idThread;
|
---|
| 49 | const char * _szFuncName;
|
---|
| 50 | const void * _pInst;
|
---|
| 51 | };
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | #ifdef _DEBUG
|
---|
| 55 | #define assert_threadmodel(entmThreadingModel) mars::ThreadingModelMonitor tmm(__FUNCTION__, this, entmThreadingModel)
|
---|
| 56 | #define register_mainthread() mars::gtmm_ThreadingModelManager.registerMainThread()
|
---|
| 57 | #else
|
---|
| 58 | #define assert_threadmodel(x)
|
---|
| 59 | #define register_mainthread()
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
| 62 | #endif |
---|