MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ await_shutdown()

void Lila::Lila::await_shutdown ( const std::atomic< bool > *  external_flag)

Blocks until server shutdown (main thread event loop)

Parameters
external_flagstd::atomic<bool> Whether to force shutdown externally

On macOS: Runs CFRunLoop to process main queue (required for JIT GLFW) On other platforms: Simple blocking wait

Should be called on main thread after initialize() in Server mode. Returns when stop_server() is called or server fails.

Definition at line 221 of file Lila.cpp.

222{
223 LILA_INFO(Emitter::SYSTEM, "Entering main event loop");
224
225#ifdef MAYAFLUX_PLATFORM_MACOS
226 while (!m_shutdown_requested.load(std::memory_order_acquire) && (!external_flag || external_flag->load(std::memory_order_acquire))) {
227 if (!is_server_running()) {
228 LILA_ERROR(Emitter::SYSTEM, "Server stopped unexpectedly");
229 break;
230 }
231 CFRunLoopRunInMode(kCFRunLoopDefaultMode, server_loop_rate, false);
232 }
233
234#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
235 if (MayaFlux::Parallel::g_MainThreadId == 0) {
236 MayaFlux::Parallel::g_MainThreadId = GetCurrentThreadId();
237 }
238
239 MSG msg;
240 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
241
242 while (!m_shutdown_requested.load(std::memory_order_acquire)
243 && (!external_flag || external_flag->load(std::memory_order_acquire))) {
244 if (!is_server_running()) {
245 LILA_ERROR(Emitter::SYSTEM, "Server stopped unexpectedly");
246 break;
247 }
248
249 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
250 if (msg.message == WM_QUIT) {
251 m_shutdown_requested.store(true, std::memory_order_release);
252 break;
253 }
254
255 if (msg.message == MAYAFLUX_WM_DISPATCH) {
256 auto* task = reinterpret_cast<std::function<void()>*>(msg.lParam);
257 if (task) {
258 (*task)();
259 delete task;
260 }
261 } else {
262 TranslateMessage(&msg);
263 DispatchMessage(&msg);
264 }
265 }
266
267 std::this_thread::sleep_for(
268 std::chrono::milliseconds(static_cast<int>(server_loop_rate * 1000.0F)));
269 }
270
271#else
272 while (!m_shutdown_requested.load(std::memory_order_acquire) && (!external_flag || external_flag->load(std::memory_order_acquire))) {
273 if (!is_server_running()) {
274 LILA_ERROR(Emitter::SYSTEM, "Server stopped unexpectedly");
275 break;
276 }
277 std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(server_loop_rate * 1000)));
278 }
279#endif
280
281 LILA_INFO(Emitter::SYSTEM, "Exiting main event loop");
282}
#define LILA_ERROR(emitter, msg)
#define LILA_INFO(emitter, msg)
float server_loop_rate
Server loop rate in seconds.
Definition Lila.hpp:211
bool is_server_running() const
Checks if the server is currently running.
Definition Lila.cpp:146
std::atomic< bool > m_shutdown_requested
Definition Lila.hpp:209

References LILA_ERROR, and LILA_INFO.

Referenced by main().

+ Here is the caller graph for this function: