IsThreadSuspended - checks if a thread is currently suspended by suspending it has its drawbacks since it suspends threads very briefly, but it works fine */
| 61 | has its drawbacks since it suspends threads very briefly, but it works fine |
| 62 | */ |
| 63 | bool Thread::IsThreadSuspended(DWORD tid) |
| 64 | { |
| 65 | if (tid == 0) |
| 66 | return false; |
| 67 | |
| 68 | bool suspended = false; |
| 69 | DWORD suspendCount = 0; |
| 70 | |
| 71 | HANDLE threadHandle = OpenThread(THREAD_SUSPEND_RESUME, FALSE, tid); |
| 72 | |
| 73 | if (threadHandle == INVALID_HANDLE_VALUE || threadHandle == 0) |
| 74 | return false; |
| 75 | |
| 76 | __try |
| 77 | { |
| 78 | suspendCount = SuspendThread(threadHandle); //warning: invalid handle will throw exception here |
| 79 | } |
| 80 | __except (EXCEPTION_EXECUTE_HANDLER) |
| 81 | { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | if (suspendCount == (DWORD)-1) |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | else if (suspendCount > 0) //already suspended by someone else |
| 90 | { |
| 91 | ResumeThread(threadHandle); |
| 92 | suspended = true; |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | ResumeThread(threadHandle); |
| 97 | } |
| 98 | |
| 99 | return suspended; |
| 100 | } |
nothing calls this directly
no outgoing calls
no test coverage detected