Skip to content

Commit 2bc5c3d

Browse files
committed
Move global Timeout object from utest_shim in static function.
The change of scope allow the linker to remove the variable if not used.
1 parent acc3115 commit 2bc5c3d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

features/frameworks/utest/source/utest_shim.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ static volatile utest_v1_harness_callback_t minimal_callback;
6666
static volatile utest_v1_harness_callback_t ticker_callback;
6767

6868
// Timeout object used to control the scheduling of test case callbacks
69-
Timeout utest_timeout_object;
69+
static Timeout& utest_timeout_object() {
70+
static Timeout timeout;
71+
return timeout;
72+
}
7073

7174
static void ticker_handler()
7275
{
@@ -88,7 +91,7 @@ static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, ti
8891
if (delay_ms) {
8992
ticker_callback = callback;
9093
// fire the interrupt in 1000us * delay_ms
91-
utest_timeout_object.attach_us(ticker_handler, delay_us);
94+
utest_timeout_object().attach_us(ticker_handler, delay_us);
9295

9396
}
9497
else {
@@ -102,7 +105,7 @@ static int32_t utest_us_ticker_cancel(void *handle)
102105
{
103106
UTEST_LOG_FUNCTION();
104107
(void) handle;
105-
utest_timeout_object.detach();
108+
utest_timeout_object().detach();
106109
return 0;
107110
}
108111
static int32_t utest_us_ticker_run()

0 commit comments

Comments
 (0)