Skip to content

Commit 6711f57

Browse files
committed
kernel/os: Add M_CHECKIF macro
This adds M_CHECKIF macro that does runtime checks or, if compiled with OS_ASSERT_ON_ERRORS option runtime asserts. OS_NO_RUNTIME_CHECKS option disables any runtime checks or asserts. The code has been copied from Zephyr and adjusted for MyNewt. Signed-off-by: MariuszSkamra <mariusz.skamra@codecoup.pl>
1 parent e776386 commit 6711f57

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

kernel/os/include/os/check.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2019 Intel Corporation
3+
* Copyright (c) 2025 Codecoup
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#ifndef OS_CHECK_H_
9+
#define OS_CHECK_H_
10+
11+
#include <assert.h>
12+
#include <syscfg/syscfg.h>
13+
14+
#if MYNEWT_VAL(OS_ASSERT_ON_ERRORS)
15+
#define M_CHECKIF(expr) \
16+
assert(!(expr)); \
17+
if (0)
18+
#elif MYNEWT_VAL(OS_NO_RUNTIME_CHECKS)
19+
#define M_CHECKIF(expr) if (0 && (expr))
20+
#else
21+
#define M_CHECKIF(expr) if (expr)
22+
#endif
23+
24+
#endif /* OS_CHECK_H_ */

kernel/os/syscfg.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ syscfg.defs:
201201
If set, run time is measured in cpu time ticks rather than OS time
202202
ticks.
203203
value: 0
204+
OS_ASSERT_ON_ERRORS:
205+
description: >
206+
Assert on errors covered with the M_CHECKIF() macro.
207+
value: 0
208+
OS_NO_RUNTIME_CHECKS:
209+
description: >
210+
Do not do any runtime checks or asserts when using the M_CHECKIF()
211+
macro.
212+
value: 0
204213

205214
syscfg.vals.OS_DEBUG_MODE:
206215
OS_CRASH_STACKTRACE: 1

0 commit comments

Comments
 (0)