GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_system_timer_update.c Lines: 22 22 100.0 %
Date: 2024-12-05 08:52:37 Branches: 12 12 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   System Management (System)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_animation.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_system_timer_update                             PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function is called when the GUIX timers need to be updated.    */
44
/*    It updates all of the GUIX application timers, and sends events     */
45
/*    as needed.                                                          */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    None                                                                */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    None                                                                */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*   _gx_system_lock                        Lock system mutex             */
58
/*   _gx_system_unlock                      Unlock system mutex           */
59
/*   [gx_widget_event_process_function]     Event handler of timer owner  */
60
/*   _gx_system_timer_stop                  Stop the system timer         */
61
/*   _gx_animation_update                   Update the animation sequence */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    tx_timer                                                            */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
8170
VOID  _gx_system_timer_update(ULONG ticks)
77
{
78
GX_TIMER  *current_timer;
79
GX_TIMER  *next_timer;
80
GX_WIDGET *timer_owner;
81
UINT       timer_id;
82
GX_EVENT   timer_event;
83
84
8170
GX_ENTER_CRITICAL
85
86
8170
    current_timer = _gx_system_active_timer_list;
87
88
8170
    timer_event.gx_event_type = GX_EVENT_TIMER;
89
90
13278
    while (current_timer)
91
    {
92
5108
        next_timer = current_timer -> gx_timer_next;
93
94
        /* has this timer expired? */
95
5108
        if (current_timer -> gx_timer_initial_ticks > ticks)
96
        {
97
            /* just decrement the timer */
98
2014
            current_timer -> gx_timer_initial_ticks -= ticks;
99
        }
100
        else
101
        {
102
            /* timer has expired, call the timer owner's event handler */
103
3094
            timer_owner = current_timer -> gx_timer_owner;
104
3094
            timer_id = current_timer -> gx_timer_id;
105
106
            /* check to see if this timer should be removed or restarted */
107
108
3094
            if (current_timer -> gx_timer_reschedule_ticks > 0)
109
            {
110
                /* reload the timer */
111
3013
                current_timer -> gx_timer_initial_ticks = current_timer -> gx_timer_reschedule_ticks;
112
            }
113
            else
114
            {
115
                /* remove the timer */
116
81
                _gx_system_timer_stop(current_timer -> gx_timer_owner, current_timer -> gx_timer_id);
117
            }
118
119

3094
            if (timer_owner != GX_NULL && timer_owner -> gx_widget_event_process_function)
120
            {
121
3088
                timer_event.gx_event_payload.gx_event_timer_id = timer_id;
122
3088
                timer_event.gx_event_target = timer_owner;
123
                /*_gx_system_event_fold(&timer_event);*/
124
3088
                _gx_system_event_send(&timer_event);
125
            }
126
        }
127
5108
        current_timer = next_timer;
128
    }
129
130
8170
    if (_gx_system_animation_list)
131
    {
132
4781
        _gx_animation_update();
133
    }
134
135
    /* release our lock */
136
8170
    GX_EXIT_CRITICAL
137
8170
}
138