MCPcopy Create free account
hub / github.com/Abc-Arbitrage/Disruptor-cpp / run

Method run

Disruptor/BatchEventProcessor.h:104–155  ·  view source on GitHub ↗

* It is ok to have another thread rerun this method after a halt(). */

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

clearAlertMethod · 0.45
valueMethod · 0.45
waitForMethod · 0.45
onEventMethod · 0.45
setValueMethod · 0.45
handleEventExceptionMethod · 0.45

Tested by

no test coverage detected