GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_system_lock.c Lines: 8 8 100.0 %
Date: 2026-03-06 19:21:09 Branches: 4 4 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
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_system_lock                                     PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function locks the GUIX system mutex                           */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    None                                                                */
48
/*                                                                        */
49
/*  OUTPUT                                                                */
50
/*                                                                        */
51
/*    None                                                                */
52
/*                                                                        */
53
/*  CALLS                                                                 */
54
/*                                                                        */
55
/*    tx_mutex_get                      Grab a mutex                      */
56
/*    _tx_thread_identify               Identify current thread           */
57
/*    _gx_system_error_process          Process an error                  */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    GUIX Internal Code                                                  */
62
/*                                                                        */
63
/**************************************************************************/
64
689246
VOID _gx_system_lock(VOID)
65
{
66
#ifdef GX_THREADX_BINDING
67
UINT protection_status;
68
#endif
69
70
    /* if the current thread already owns the GUIX system protection
71
       then we don't need to lock again, just increment our nesting counter.
72
       If no thread has yet locked GUIX or if the caller is not the owning
73
       thread, then we need to request the gx_system_protect mutex.
74
     */
75
76
689246
    if (_gx_system_lock_thread != GX_CURRENT_THREAD)
77
    {
78
#ifdef GX_THREADX_BINDING
79
467227
        protection_status =  tx_mutex_get(&_gx_system_protect, TX_WAIT_FOREVER);
80
        /* Determine if we successfully obtained the protection.  */
81
467227
        if (protection_status)
82
        {
83
            /* Error obtaining protection - call system error handler.  */
84
1
            _gx_system_error_process(GX_SYSTEM_PROTECTION_ERROR);
85
86
            /* Return to exit the system thread.  */
87
1
            return;
88
        }
89
#else
90
        GX_SYSTEM_MUTEX_LOCK;
91
#endif
92
93
94
95
        /* save which thread owns the GUIX locked */
96
467226
        _gx_system_lock_thread = GX_CURRENT_THREAD;
97
    }
98
689245
    _gx_system_lock_nesting++;
99
}
100