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 |
|
|
|
29 |
|
|
|
30 |
|
|
/**************************************************************************/ |
31 |
|
|
/* */ |
32 |
|
|
/* FUNCTION RELEASE */ |
33 |
|
|
/* */ |
34 |
|
|
/* _gx_system_lock PORTABLE C */ |
35 |
|
|
/* 6.1 */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* This function locks the GUIX system mutex */ |
43 |
|
|
/* */ |
44 |
|
|
/* INPUT */ |
45 |
|
|
/* */ |
46 |
|
|
/* None */ |
47 |
|
|
/* */ |
48 |
|
|
/* OUTPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* None */ |
51 |
|
|
/* */ |
52 |
|
|
/* CALLS */ |
53 |
|
|
/* */ |
54 |
|
|
/* tx_mutex_get Grab a mutex */ |
55 |
|
|
/* _tx_thread_identify Identify current thread */ |
56 |
|
|
/* _gx_system_error_process Process an error */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLED BY */ |
59 |
|
|
/* */ |
60 |
|
|
/* GUIX Internal Code */ |
61 |
|
|
/* */ |
62 |
|
|
/* RELEASE HISTORY */ |
63 |
|
|
/* */ |
64 |
|
|
/* DATE NAME DESCRIPTION */ |
65 |
|
|
/* */ |
66 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
67 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
68 |
|
|
/* resulting in version 6.1 */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
689097 |
VOID _gx_system_lock(VOID) |
72 |
|
|
{ |
73 |
|
|
#ifdef GX_THREADX_BINDING |
74 |
|
|
UINT protection_status; |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
/* if the current thread already owns the GUIX system protection |
78 |
|
|
then we don't need to lock again, just increment our nesting counter. |
79 |
|
|
If no thread has yet locked GUIX or if the caller is not the owning |
80 |
|
|
thread, then we need to request the gx_system_protect mutex. |
81 |
|
|
*/ |
82 |
|
|
|
83 |
✓✓ |
689097 |
if (_gx_system_lock_thread != GX_CURRENT_THREAD) |
84 |
|
|
{ |
85 |
|
|
#ifdef GX_THREADX_BINDING |
86 |
|
467083 |
protection_status = tx_mutex_get(&_gx_system_protect, TX_WAIT_FOREVER); |
87 |
|
|
/* Determine if we successfully obtained the protection. */ |
88 |
✓✓ |
467083 |
if (protection_status) |
89 |
|
|
{ |
90 |
|
|
/* Error obtaining protection - call system error handler. */ |
91 |
|
1 |
_gx_system_error_process(GX_SYSTEM_PROTECTION_ERROR); |
92 |
|
|
|
93 |
|
|
/* Return to exit the system thread. */ |
94 |
|
1 |
return; |
95 |
|
|
} |
96 |
|
|
#else |
97 |
|
|
GX_SYSTEM_MUTEX_LOCK; |
98 |
|
|
#endif |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
/* save which thread owns the GUIX locked */ |
103 |
|
467082 |
_gx_system_lock_thread = GX_CURRENT_THREAD; |
104 |
|
|
} |
105 |
|
689096 |
_gx_system_lock_nesting++; |
106 |
|
|
} |
107 |
|
|
|