MCPcopy Create free account
hub / github.com/GNOME/gjs / spin

Method spin

gjs/mainloop.cpp:15–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace Gjs {
14
15bool MainLoop::spin(GjsContextPrivate* gjs) {
16 if (m_exiting)
17 return false;
18
19 // Check if System.exit() has been called.
20 if (gjs->should_exit(nullptr)) {
21 // Return false to indicate the loop is exiting due to an exit call,
22 // the queue is likely not empty
23 debug("Not spinning loop because System.exit called");
24 exit();
25 return false;
26 }
27
28 Gjs::AutoPointer<GMainContext, GMainContext, g_main_context_unref>
29 main_context{g_main_context_ref_thread_default()};
30
31 debug("Spinning loop until released or hook cleared");
32 do {
33 bool blocking = can_block();
34
35 // Only run the loop if there are pending jobs.
36 if (g_main_context_pending(main_context))
37 g_main_context_iteration(main_context, blocking);
38
39 // If System.exit() has not been called
40 if (gjs->should_exit(nullptr)) {
41 debug("Stopped spinning loop because System.exit called");
42 exit();
43 return false;
44 }
45 } while (
46 // and there is not a pending main loop hook
47 !gjs->has_main_loop_hook() &&
48 // and there are pending sources or the job queue is not empty
49 // continue spinning the event loop.
50 (can_block() || !gjs->empty()));
51
52 return true;
53}
54
55}; // namespace Gjs

Callers 3

GjsContextPrivateMethod · 0.80
evalMethod · 0.80
eval_moduleMethod · 0.80

Calls 4

should_exitMethod · 0.80
has_main_loop_hookMethod · 0.80
emptyMethod · 0.80
debugFunction · 0.50

Tested by

no test coverage detected