GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_system_thread_entry.c Lines: 31 31 100.0 %
Date: 2026-03-06 19:21:09 Branches: 15 15 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   System Management (System)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
30
#if !defined(GX_THREAD_SLEEPING)
31
#define GX_THREAD_SLEEPING
32
#endif
33
34
#if !defined(GX_THREAD_AWAKE)
35
#define GX_THREAD_AWAKE
36
#endif
37
38
/**************************************************************************/
39
/*                                                                        */
40
/*  FUNCTION                                               RELEASE        */
41
/*                                                                        */
42
/*    _gx_system_thread_entry                             PORTABLE C      */
43
/*                                                           6.1          */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    Kenneth Maxwell, Microsoft Corporation                              */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This is the main processing thread for GUIX. All events and drawing */
51
/*    are done from the context of this thread.                           */
52
/*                                                                        */
53
/*  INPUT                                                                 */
54
/*                                                                        */
55
/*    id                                    Thread ID                     */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    None                                                                */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    tx_mutex_get                          Get protection mutex          */
64
/*    tx_mutex_put                          Release protection mutex      */
65
/*    tx_queue_receive                      Receive GUIX events from queue*/
66
/*    _gx_system_dirty_mark                 Mark a widget as dirty        */
67
/*    _gx_system_error_process              Process system errors         */
68
/*    _gx_system_event_dispatch             Dispatch GUIX events          */
69
/*    _gx_system_canvas_refresh             Refresh the canvas            */
70
/*    _gx_system_timer_update               Update active system timers   */
71
/*                                                                        */
72
/*  CALLED BY                                                             */
73
/*                                                                        */
74
/*    ThreadX                                                             */
75
/*                                                                        */
76
/**************************************************************************/
77
727
VOID  _gx_system_thread_entry(ULONG id)
78
{
79
80
727
UINT status = GX_FAILURE;
81
82
#ifdef GX_THREADX_BINDING
83
ULONG    event_memory[GX_EVENT_ULONGS];
84
#else
85
GX_EVENT event_memory;
86
#endif
87
88
GX_EVENT  *event_ptr;
89
GX_WIDGET *widget;
90
91
    GX_PARAMETER_NOT_USED(id);
92
93
    /* Loop to process GUIX events.  */
94
    while (1)
95
    {
96
#ifdef GX_THREADX_BINDING
97
        /* Pickup event from event queue.  */
98
159973
        status =  tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_NO_WAIT);
99
100
        /* Was there an event?  */
101
159973
        if (status == TX_QUEUE_EMPTY)
102
        {
103
            /* No event to process, so re-draw dirty widgets */
104
148530
            _gx_system_canvas_refresh();
105
106
            /* Now block this thread until an event is received.  */
107
            GX_THREAD_SLEEPING
108
148530
            status = tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_WAIT_FOREVER);
109
147806
            if (status == TX_SUCCESS)
110
            {
111
147805
                status = GX_SUCCESS;
112
            }
113
        }
114
#else
115
        /* here for generic RTOS binding */
116
        status = GX_EVENT_POP(&event_memory, GX_FALSE);
117
        if (status == GX_FAILURE)
118
        {
119
            _gx_system_canvas_refresh();
120
            GX_THREAD_SLEEPING
121
            status = GX_EVENT_POP(&event_memory, GX_TRUE);
122
        }
123
#endif
124
125
        /* Check for a successful status.  */
126
159249
        if (status == GX_SUCCESS)
127
        {
128
            GX_THREAD_AWAKE
129
            /* Setup a pointer to the event.  */
130
159248
            event_ptr =  (GX_EVENT *)(&event_memory);
131
132

159248
            switch (event_ptr -> gx_event_type)
133
            {
134
            /* Determine if a redraw event is present.  */
135
76018
            case GX_EVENT_REDRAW:
136
                /* Yes, a redraw event is present, detect and process the dirty area(s).  */
137
76018
                widget = (GX_WIDGET *)_gx_system_root_window_created_list;
138
207740
                while (widget)
139
                {
140
131722
                    _gx_system_dirty_mark(widget);
141
131722
                    widget = widget -> gx_widget_next;
142
                }
143
76018
                break;
144
145
1
            case GX_EVENT_TERMINATE:
146
1
                return;
147
148
11351
            case GX_EVENT_TIMER:
149
11351
                if (event_ptr ->gx_event_target == GX_NULL)
150
                {
151
                    /* the event is from gx_system_timer_expiration */
152
8241
                    _gx_system_timer_update(event_ptr -> gx_event_payload.gx_event_ulongdata);
153
                }
154
                else
155
                {
156
3110
                    _gx_system_event_dispatch(event_ptr);
157
                }
158
11351
                break;
159
160
368
            case 0:
161
                /* the event has been purged */
162
368
                break;
163
164
71510
            default:
165
                /* Dispatch the event to GUIX proper window/widget.  */
166
71510
                _gx_system_event_dispatch(event_ptr);
167
71509
                break;
168
            }
169
        }
170
        else
171
        {
172
            /* Error receiving event - call system error handler.  */
173
1
            _gx_system_error_process(GX_SYSTEM_EVENT_RECEIVE_ERROR);
174
175
            /* Return to exit the system thread.  */
176
1
            return;
177
        }
178
    }
179
}
180