#[repr(C, align(8))]pub struct LogEntry {
seq: AtomicUsize,
level: LogLevel,
cpu_id: usize,
length: usize,
task_id: u32,
timestamp: usize,
message: [u8; 256],
}Expand description
带有元数据和消息的单个日志条目
该结构体经过精心布局,用于无锁同步:
seq字段用作生产者和消费者之间的同步点- 带有 8 字节对齐的 C 表示形式确保了正确的原子访问
- 字段顺序经过优化以最小化填充
Fields§
§seq: AtomicUsize用于同步的序列号(必须是第一个字段)
level: LogLevel日志级别 (Emergency, Error, Info, 等)
cpu_id: usize生成此日志的 CPU ID
length: usize消息的实际长度(以字节为单位)
task_id: u32生成此日志的任务/进程 ID
timestamp: usize创建日志时的时间戳
message: [u8; 256]用于日志消息的固定大小缓冲区
Implementations§
Source§impl LogEntry
impl LogEntry
Source§impl LogEntry
impl LogEntry
Sourcepub(super) unsafe fn copy_data_to(&self, dest: *mut LogEntry)
pub(super) unsafe fn copy_data_to(&self, dest: *mut LogEntry)
将日志数据复制到缓冲区槽中(供内部使用)
复制除 seq 字段外的所有字段,seq 字段必须
通过 publish() 单独设置,以确保正确的内存顺序。
§安全性
dest 必须指向环形缓冲区中有效的 LogEntry
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LogEntry
impl RefUnwindSafe for LogEntry
impl Send for LogEntry
impl Sync for LogEntry
impl Unpin for LogEntry
impl UnwindSafe for LogEntry
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)