|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2019 [email protected]
4: //
5:
6: #pragma once
7:
8: #include <condition_variable>
9: #include <mutex>
10:
11: // デバッガプロンプトについての条件変数
12: class CVPrompt
13: {
14: public:
15: // プロンプトを出してよいというCPUからの通知
16: void NotifyAcquire()
17: {
18: std::unique_lock<std::mutex> lk(mtx);
19: is_prompt = true;
20: cvAcquire.notify_one();
21: }
22:
1.1.1.2 ! root 23: // CPU がプロンプトを出してよいと言うまで待つ。
! 24: // プロンプトを出して良いときは true を返す。
! 25: // タイムアウトすると false を返す。
! 26: bool WaitAcquire(int timeoutmsec)
1.1 root 27: {
1.1.1.2 ! root 28: std::chrono::milliseconds timeout(timeoutmsec);
! 29: std::unique_lock<std::mutex> lk(mtx);
! 30: cvAcquire.wait_for(lk, timeout, [&] { return is_prompt; });
! 31: return is_prompt;
1.1 root 32: }
33:
34: // プロンプト終了したことをCPUに通知
35: void NotifyRelease()
36: {
37: std::unique_lock<std::mutex> lk(mtx);
38: is_prompt = false;
39: cvRelease.notify_one();
40: }
41:
42: // プロンプト終了を待つ
43: void WaitRelease()
44: {
45: std::unique_lock<std::mutex> lk(mtx);
46: cvRelease.wait(lk, [&] { return !is_prompt; });
47: }
48:
49: // プロンプト出している状態なら true を返す
50: bool IsPrompt() const {
51: return is_prompt;
52: }
53:
54: private:
1.1.1.2 ! root 55: volatile bool is_prompt = false; // プロンプト中なら true
1.1 root 56: std::mutex mtx;
57: std::condition_variable cvAcquire;
58: std::condition_variable cvRelease;
59: };
60:
61: // debugger.cpp で初期化
62: extern CVPrompt *gCVPrompt;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.