mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-11 00:46:49 +00:00
new: 简单的warn assert
This commit is contained in:
parent
9ed3eb2ae2
commit
a1c843cd3a
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -107,7 +107,8 @@
|
|||||||
"libm.h": "c",
|
"libm.h": "c",
|
||||||
"ahci.h": "c",
|
"ahci.h": "c",
|
||||||
"slab.h": "c",
|
"slab.h": "c",
|
||||||
"boot_info.h": "c"
|
"boot_info.h": "c",
|
||||||
|
"pci.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "Enabled",
|
"C_Cpp.errorSquiggles": "Enabled",
|
||||||
"esbonio.sphinx.confDir": ""
|
"esbonio.sphinx.confDir": ""
|
||||||
|
10
kernel/common/compiler.h
Normal file
10
kernel/common/compiler.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define likely(x) __builtin_expect(!!(x), 1)
|
||||||
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
|
|
||||||
|
#ifndef barrier
|
||||||
|
// 内存屏障
|
||||||
|
#define barrier() __asm__ __volatile__("" :: \
|
||||||
|
: "memory");
|
||||||
|
#endif
|
14
kernel/debug/bug.h
Normal file
14
kernel/debug/bug.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <common/compiler.h>
|
||||||
|
#include <common/kprint.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 当condition为true时输出警告信息
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define WARN_ON(condition) ({ \
|
||||||
|
int __ret_warn_on = !!(condition); \
|
||||||
|
if (unlikely(__ret_warn_on)) \
|
||||||
|
kwarn("Assertion failed at %s:%d", __FILE__, __LINE__); \
|
||||||
|
unlikely(__ret_warn_on); \
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user