LCOV - code coverage report
Current view: top level - gjs - mainloop.cpp (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 100.0 % 20 20
Test Date: 2024-03-26 02:45:07 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 93.8 % 16 15

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2021 Evan Welsh <contact@evanwelsh.com>
       4                 :             : 
       5                 :             : #include <config.h>
       6                 :             : 
       7                 :             : #include <glib.h>
       8                 :             : 
       9                 :             : #include "gjs/context-private.h"
      10                 :             : #include "gjs/jsapi-util.h"
      11                 :             : #include "gjs/mainloop.h"
      12                 :             : 
      13                 :             : namespace Gjs {
      14                 :             : 
      15                 :         581 : bool MainLoop::spin(GjsContextPrivate* gjs) {
      16         [ +  + ]:         581 :     if (m_exiting)
      17                 :           1 :         return false;
      18                 :             : 
      19                 :             :     // Check if System.exit() has been called.
      20         [ +  + ]:         580 :     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                 :           1 :         debug("Not spinning loop because System.exit called");
      24                 :           1 :         exit();
      25                 :           1 :         return false;
      26                 :             :     }
      27                 :             : 
      28                 :             :     GjsAutoPointer<GMainContext, GMainContext, g_main_context_unref>
      29                 :         579 :         main_context(g_main_context_ref_thread_default());
      30                 :             : 
      31                 :         579 :     debug("Spinning loop until released or hook cleared");
      32                 :             :     do {
      33                 :         877 :         bool blocking = can_block();
      34                 :             : 
      35                 :             :         // Only run the loop if there are pending jobs.
      36         [ +  + ]:         877 :         if (g_main_context_pending(main_context))
      37                 :         438 :             g_main_context_iteration(main_context, blocking);
      38                 :             : 
      39                 :             :         // If System.exit() has not been called
      40         [ +  + ]:         877 :         if (gjs->should_exit(nullptr)) {
      41                 :           3 :             debug("Stopped spinning loop because System.exit called");
      42                 :           3 :             exit();
      43                 :           3 :             return false;
      44                 :             :         }
      45                 :             :     } while (
      46                 :             :         // and there is not a pending main loop hook
      47   [ +  +  +  +  :        2320 :         !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         [ -  + ]:        1446 :         (can_block() || !gjs->empty()));
      51                 :             : 
      52                 :         576 :     return true;
      53                 :         579 : }
      54                 :             : 
      55                 :             : };  // namespace Gjs
        

Generated by: LCOV version 2.0-1