| 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 | #include "ThreadDebugging.hxx" | 
|---|
| 19 |  | 
|---|
| 20 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 21 | ThreadDebuggingHelper::ThreadDebuggingHelper() | 
|---|
| 22 | : myMainThreadIdConfigured(false) | 
|---|
| 23 | { | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 27 | ThreadDebuggingHelper& ThreadDebuggingHelper::instance() | 
|---|
| 28 | { | 
|---|
| 29 | static ThreadDebuggingHelper instance; | 
|---|
| 30 |  | 
|---|
| 31 | return instance; | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 35 | void ThreadDebuggingHelper::fail(const string& message) | 
|---|
| 36 | { | 
|---|
| 37 | cerr << message << endl; | 
|---|
| 38 |  | 
|---|
| 39 | throw runtime_error(message); | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 43 | void ThreadDebuggingHelper::setMainThread() | 
|---|
| 44 | { | 
|---|
| 45 | if (myMainThreadIdConfigured) fail( "main thread already configured"); | 
|---|
| 46 |  | 
|---|
| 47 | myMainThreadIdConfigured = true; | 
|---|
| 48 | myMainThreadId = std::this_thread::get_id(); | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 52 | void ThreadDebuggingHelper::assertMainThread() | 
|---|
| 53 | { | 
|---|
| 54 | if (!myMainThreadIdConfigured) fail( "main thread not configured"); | 
|---|
| 55 |  | 
|---|
| 56 | if (std::this_thread::get_id() != myMainThreadId) fail( "must be called from main thread"); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|