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

◆ await_shutdown()

void MayaFlux::Core::Engine::await_shutdown ( )

Blocks until shutdown is requested (main thread event loop)

Pumps platform-specific events on the main thread and waits for shutdown. On macOS: Runs CFRunLoop to service the main dispatch queue (required for AppKit) On other platforms: Simple blocking wait for user input

Should be called on the main thread after Start().

Definition at line 204 of file Engine.cpp.

205{
206#ifdef MAYAFLUX_PLATFORM_MACOS
207 run_macos_event_loop();
208#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
209 static HANDLE s_shutdown_event = CreateEventW(nullptr, TRUE, FALSE, nullptr);
210 if (!s_shutdown_event) {
212 "Failed to create shutdown event (GetLastError={}), cannot await Ctrl-C", GetLastError());
213 return;
214 }
215 ResetEvent(s_shutdown_event);
216
217 SetConsoleCtrlHandler([](DWORD type) -> BOOL {
218 if (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT || type == CTRL_CLOSE_EVENT) {
219 SetEvent(s_shutdown_event);
220 return TRUE;
221 }
222 return FALSE;
223 },
224 TRUE);
225
226 WaitForSingleObject(s_shutdown_event, INFINITE);
227#else
228 static std::atomic<bool> s_signal_received { false };
229 s_signal_received.store(false, std::memory_order_relaxed);
230
231 sigset_t block_mask, orig_mask;
232 sigemptyset(&block_mask);
233 sigaddset(&block_mask, SIGINT);
234 sigaddset(&block_mask, SIGTERM);
235 pthread_sigmask(SIG_BLOCK, &block_mask, &orig_mask);
236
237 struct sigaction sa {};
238 sigemptyset(&sa.sa_mask);
239 sa.sa_handler = [](int) { s_signal_received.store(true, std::memory_order_release); };
240 sigaction(SIGINT, &sa, nullptr);
241 sigaction(SIGTERM, &sa, nullptr);
242
243 while (!s_signal_received.load(std::memory_order_acquire)) {
244 sigsuspend(&orig_mask);
245 }
246
247 pthread_sigmask(SIG_SETMASK, &orig_mask, nullptr);
248#endif
249
250 m_should_shutdown.store(true, std::memory_order_release);
251
253 "Shutdown requested, awaiting all subsystem termination ......");
254}
#define MF_LOG(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
vk::PhysicalDeviceType type
Definition VKDevice.cpp:126
std::atomic< bool > m_should_shutdown
Definition Engine.hpp:393
@ Runtime
General runtime operations (default fallback)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, m_should_shutdown, MF_ERROR, MF_LOG, MayaFlux::Journal::Runtime, and type.

Referenced by MayaFlux::Await().

+ Here is the caller graph for this function: