MayaFlux 0.4.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 228 of file Lila.cpp.

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

References LILA_ERROR, and LILA_INFO.

Referenced by main().

+ Here is the caller graph for this function: