| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include "mos/misc/panic.hpp" |
| 6 | |
| 7 | #include <mos/mos_global.h> |
| 8 | |
| 9 | #define MOS_UNIMPLEMENTED(content) mos_panic("\nUNIMPLEMENTED: %s", content) |
| 10 | #define MOS_UNREACHABLE() mos_panic("\nUNREACHABLE line %d reached in file: %s", __LINE__, __FILE__) |
| 11 | #define MOS_UNREACHABLE_X(msg, ...) mos_panic("\nUNREACHABLE line %d reached in file: %s\n" msg, __LINE__, __FILE__, ##__VA_ARGS__) |
| 12 | #define MOS_ASSERT_X(cond, msg, ...) \ |
| 13 | do \ |
| 14 | { \ |
| 15 | if (unlikely(!(cond))) \ |
| 16 | mos_panic_inline("Assertion failed: %s\n" msg, #cond, ##__VA_ARGS__); \ |
| 17 | } while (0) |
| 18 | #define MOS_ASSERT_ONCE(...) MOS_ASSERT_X(once(), __VA_ARGS__) |
| 19 | #define MOS_ASSERT(cond) MOS_ASSERT_X(cond, "") |
| 20 | |
| 21 | // these two also invokes a warning/panic handler |
| 22 | #define mos_warn(fmt, ...) mos_kwarn(__func__, __LINE__, "WARN: " fmt "\r\n", ##__VA_ARGS__) |
| 23 | |
| 24 | #define mos_warn_once(...) \ |
| 25 | do \ |
| 26 | { \ |
| 27 | if (once()) \ |
| 28 | mos_warn(__VA_ARGS__); \ |
| 29 | } while (0) |
| 30 | |
| 31 | #define spinlock_assert_locked(lock) MOS_ASSERT(spinlock_is_locked(lock)) |
| 32 | |
| 33 | __printf(3, 4) void mos_kwarn(const char *func, u32 line, const char *fmt, ...); |
| 34 | |