| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #ifndef THREADING_DEBUGGER_HXX |
| 19 | #define THREADING_DEBUGGER_HXX |
| 20 | |
| 21 | #include <thread> |
| 22 | |
| 23 | #include "bspf.hxx" |
| 24 | |
| 25 | #ifdef DEBUG_BUILD |
| 26 | |
| 27 | #define SET_MAIN_THREAD ThreadDebuggingHelper::instance().setMainThread(); |
| 28 | #define ASSERT_MAIN_THREAD ThreadDebuggingHelper::instance().assertMainThread(); |
| 29 | |
| 30 | #else |
| 31 | |
| 32 | #define SET_MAIN_THREAD |
| 33 | #define ASSERT_MAIN_THREAD |
| 34 | |
| 35 | #endif |
| 36 | |
| 37 | class ThreadDebuggingHelper { |
| 38 | |
| 39 | public: |
| 40 | |
| 41 | void setMainThread(); |
| 42 | |
| 43 | void assertMainThread(); |
| 44 | |
| 45 | static ThreadDebuggingHelper& instance(); |
| 46 | |
| 47 | private: |
| 48 | |
| 49 | [[noreturn]] void fail(const string& message); |
| 50 | |
| 51 | ThreadDebuggingHelper(); |
| 52 | |
| 53 | std::thread::id myMainThreadId; |
| 54 | |
| 55 | bool myMainThreadIdConfigured; |
| 56 | |
| 57 | private: |
| 58 | |
| 59 | ThreadDebuggingHelper(const ThreadDebuggingHelper&) = delete; |
| 60 | ThreadDebuggingHelper(ThreadDebuggingHelper&&) = delete; |
| 61 | ThreadDebuggingHelper& operator=(const ThreadDebuggingHelper&) = delete; |
| 62 | ThreadDebuggingHelper& operator=(ThreadDebuggingHelper&&) = delete; |
| 63 | }; |
| 64 | |
| 65 | #endif // THREADING_DEBUGGER_HXX |
| 66 | |