1 |
/* |
/* |
2 |
* LSCP Shell |
* LSCP Shell |
3 |
* |
* |
4 |
* Copyright (c) 2014 - 2017 Christian Schoenebeck |
* Copyright (c) 2014 - 2020 Christian Schoenebeck |
5 |
* |
* |
6 |
* This program is part of LinuxSampler and released under the same terms. |
* This program is part of LinuxSampler and released under the same terms. |
7 |
*/ |
*/ |
37 |
} |
} |
38 |
|
|
39 |
int KeyboardReader::Main() { |
int KeyboardReader::Main() { |
40 |
|
#if DEBUG |
41 |
|
Thread::setNameOfCaller("KeyboardReader"); |
42 |
|
#endif |
43 |
|
|
44 |
while (true) { |
while (true) { |
45 |
std::vector<char> v = TerminalCtrl::getChars(1, 1); |
std::vector<char> v = TerminalCtrl::getChars(1, 1); |
46 |
if (!v.empty()) { |
if (!v.empty()) { |
47 |
|
// prevent thread from being cancelled |
48 |
|
// (e.g. to prevent deadlocks while holding mutex lock(s)) |
49 |
|
pushCancelable(false); |
50 |
|
|
51 |
m_fifoMutex.Lock(); |
m_fifoMutex.Lock(); |
52 |
m_fifo.push_back(v[0]); |
m_fifo.push_back(v[0]); |
53 |
if (m_sync.GetUnsafe()) { |
if (m_sync.GetUnsafe()) { |
64 |
m_fifoMutex.Unlock(); |
m_fifoMutex.Unlock(); |
65 |
if (m_callback && m_doCallback) (*m_callback)(this); |
if (m_callback && m_doCallback) (*m_callback)(this); |
66 |
} |
} |
67 |
|
|
68 |
|
// now allow thread being cancelled again |
69 |
|
// (since all mutexes are now unlocked) |
70 |
|
popCancelable(); |
71 |
} |
} |
72 |
TestCancel(); |
TestCancel(); |
73 |
} |
} |