| 57 | } |
| 58 | } |
| 59 | bool RequestToSend::request() { |
| 60 | BOOST_ASSERT_MSG(m_calledRequest == false, |
| 61 | "Can only try to request once " |
| 62 | "on a single RequestToSend " |
| 63 | "object lifetime"); |
| 64 | { |
| 65 | m_lock.lock(); |
| 66 | if (true == m_sharedRts && |
| 67 | m_control.m_currentRequestThread == |
| 68 | boost::this_thread::get_id()) { |
| 69 | /// OK, so we're recursive here. Make a note and don't add |
| 70 | /// another locking layer |
| 71 | m_nested = true; |
| 72 | m_lock.unlock(); |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | BOOST_ASSERT_MSG(m_sharedRts == false, |
| 77 | "Shouldn't happen - inconsistent " |
| 78 | "state. Can't get in a request when " |
| 79 | "already in one."); |
| 80 | m_sharedRts = true; |
| 81 | m_sharedDone = false; |
| 82 | m_calledRequest = true; |
| 83 | /// Take the main thread "free to go" status lock. |
| 84 | { |
| 85 | m_lockDone.lock(); |
| 86 | m_sharedDone = false; |
| 87 | while (m_mainMessage == AsyncAccessControl::MTM_WAIT) { |
| 88 | m_condAsyncThread.wait( |
| 89 | m_lock); // In here we unlock the mutex |
| 90 | // until we are notified. |
| 91 | } |
| 92 | // The mutex is locked again here, until the destructor. |
| 93 | |
| 94 | // Get the return value. |
| 95 | auto ret = |
| 96 | (m_mainMessage == AsyncAccessControl::MTM_CLEAR_TO_SEND); |
| 97 | if (ret) { |
| 98 | BOOST_ASSERT_MSG( |
| 99 | !m_control.m_currentRequestThread.is_initialized(), |
| 100 | "Shouldn't be anyone in except us!"); |
| 101 | m_control.m_currentRequestThread = |
| 102 | boost::this_thread::get_id(); |
| 103 | } |
| 104 | return ret; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | AsyncAccessControl::AsyncAccessControl() |
| 110 | : m_rts(false), m_done(false), m_mainMessage(MTM_WAIT) {} |
no test coverage detected