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