* It is ok to have another thread rerun this method after a halt(). */
| 102 | * It is ok to have another thread rerun this method after a halt(). |
| 103 | */ |
| 104 | void run() override |
| 105 | { |
| 106 | if (m_running.exchange(true) != false) |
| 107 | { |
| 108 | DISRUPTOR_THROW_INVALID_OPERATION_EXCEPTION("Thread is already running"); |
| 109 | } |
| 110 | |
| 111 | m_sequenceBarrierRef.clearAlert(); |
| 112 | |
| 113 | notifyStart(); |
| 114 | |
| 115 | auto nextSequence = m_sequenceRef.value() + 1; |
| 116 | |
| 117 | T* evt = nullptr; |
| 118 | |
| 119 | while (true) |
| 120 | { |
| 121 | try |
| 122 | { |
| 123 | auto availableSequence = m_sequenceBarrierRef.waitFor(nextSequence); |
| 124 | |
| 125 | while (nextSequence <= availableSequence) |
| 126 | { |
| 127 | evt = &m_dataProviderRef[nextSequence]; |
| 128 | m_eventHandlerRef.onEvent(*evt, nextSequence, nextSequence == availableSequence); |
| 129 | nextSequence++; |
| 130 | } |
| 131 | |
| 132 | m_sequenceRef.setValue(availableSequence); |
| 133 | } |
| 134 | catch (const TimeoutException&) |
| 135 | { |
| 136 | notifyTimeout(m_sequenceRef.value()); |
| 137 | } |
| 138 | catch (const AlertException&) |
| 139 | { |
| 140 | if (m_running == false) |
| 141 | { |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | catch (const std::exception& ex) |
| 146 | { |
| 147 | m_exceptionHandler->handleEventException(ex, nextSequence, *evt); |
| 148 | m_sequenceRef.setValue(nextSequence); |
| 149 | nextSequence++; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | notifyShutdown(); |
| 154 | m_running = false; |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | void notifyTimeout(std::int64_t availableSequence) const |
nothing calls this directly
no test coverage detected