diff options
| author | zy <[email protected]> | 2023-09-13 02:27:55 +0000 |
|---|---|---|
| committer | zy <[email protected]> | 2023-09-13 02:27:55 +0000 |
| commit | 2e7f7f02b9aad124f530a57b214e4ddf38a72ba1 (patch) | |
| tree | 12bf2d00ad597019646febd3fcde6cd29c01da3f /src/timeout.rs | |
| parent | ca8e89aadbf0ca8c1b8326c7cde13baf159cccb3 (diff) | |
timeouts_it 等定义
Diffstat (limited to 'src/timeout.rs')
| -rw-r--r-- | src/timeout.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/timeout.rs b/src/timeout.rs index 29cfcd0..b331f1f 100644 --- a/src/timeout.rs +++ b/src/timeout.rs @@ -24,8 +24,7 @@ extern "C" { /// I N T E G E R T Y P E I N T E R F A C E S // TODO 原为宏定义, 使用静态变量代替 需进一步检查 -pub type timeout_t = u64; -pub const TIMEOUT_PRIu: &[u8; 2] = b"lu"; +pub const TIMEOUT_PRIu: &[u8; 2] = b"lu"; // C 语言字符串结尾 `\0`, rust 没有 pub const TIMEOUT_PRIx: &[u8; 2] = b"lx"; pub const TIMEOUT_PRIX: &[u8; 2] = b"lX"; @@ -33,6 +32,7 @@ pub const TIMEOUT_mHZ: u64 = 1000; pub const TIMEOUT_uHZ: u64 = 1000000; pub const TIMEOUT_nHZ: u64 = 1000000000; +pub type timeout_t = u64; pub type timeout_error_t = usize; /// C A L L B A C K I N T E R F A C E @@ -50,18 +50,22 @@ pub struct timeout_cb { /// T I M E O U T I N T E R F A C E S +// #[cfg(TIMEOUT_DISABLE_INTERVALS)] pub const TIMEOUT_INT: u32 = 1; pub const TIMEOUT_ABS: u32 = 2; +// TODO 宏定义 TIMEOUT_INITIALIZER timeout_setcb + +// 原定义在 timeout.c #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct timeout_list { pub _address: u8, } - +// 来自 TAILQ_ENTRY 宏 #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct timeout__bindgen_ty_1 { +pub struct timeout_TAILQ_ENTRY { pub tqe_next: *mut timeout, pub tqe_prev: *mut *mut timeout, } @@ -72,7 +76,7 @@ pub struct timeout { pub flags: c_int, pub expires: timeout_t, /* absolute expiration time */ pub pending: *mut timeout_list, /* timeout list if pending on wheel or expiry queue */ - pub tqe: timeout__bindgen_ty_1, /* entry member for struct timeout_list lists */ + pub tqe: timeout_TAILQ_ENTRY, /* entry member for struct timeout_list lists */ // #[cfg(TIMEOUT_DISABLE_CALLBACKS)] pub callback: timeout_cb, /* optional callback information */ // #[cfg(TIMEOUT_DISABLE_INTERVALS)] @@ -85,7 +89,7 @@ extern "C" { /* initialize timeout structure (same as TIMEOUT_INITIALIZER) */ pub fn timeout_init(arg1: *mut timeout, arg2: c_int) -> *mut timeout; } -#[cfg(TIMEOUT_DISABLE_RELATIVE_ACCESS)] +// #[cfg(TIMEOUT_DISABLE_RELATIVE_ACCESS)] #[link(name = "timeout")] extern "C" { /* true if on timing wheel, false otherwise */ @@ -107,7 +111,7 @@ pub struct timeouts { #[link(name = "timeout")] extern "C" { /* open a new timing wheel, setting optional HZ (for float conversions) */ - pub fn timeouts_open(arg1: timeout_t, arg2: *mut c_int) -> *mut timeouts; + pub fn timeouts_open(arg1: timeout_t, arg2: *mut timeout_error_t) -> *mut timeouts; /* destroy timing wheel */ pub fn timeouts_close(arg1: *mut timeouts); /* return HZ setting (for float conversions) */ @@ -138,7 +142,7 @@ pub const TIMEOUTS_EXPIRED: u32 = 32; pub const TIMEOUTS_ALL: u32 = 48; pub const TIMEOUTS_CLEAR: u32 = 64; -// 原为 C 的宏定义, FFI 绑定只能转为 C 兼容函数 +// 原为 C 的宏定义 能转为 C 兼容函数 #[no_mangle] pub extern "C" fn TIMEOUTS_IT_INITIALIZER(flags: c_int) -> timeouts_it { timeouts_it { @@ -149,7 +153,7 @@ pub extern "C" fn TIMEOUTS_IT_INITIALIZER(flags: c_int) -> timeouts_it { to: null_mut(), } } -// 原为 C 的宏定义, FFI 绑定只能转为 C 兼容函数 +// 原为 C 的宏定义 能转为 C 兼容函数 #[no_mangle] pub extern "C" fn TIMEOUTS_IT_INIT(cur: *mut timeouts_it, flags: i32) { unsafe { @@ -168,6 +172,16 @@ pub struct timeouts_it { pub to: *mut timeout, } +/* return next timeout in pending wheel or expired queue. caller can delete + * the returned timeout, but should not otherwise manipulate the timing + * wheel. in particular, caller SHOULD NOT delete any other timeout as that + * could invalidate cursor state and trigger a use-after-free. + */ +#[link(name = "timeout")] +extern "C" { + pub fn timeouts_next(arg1: *mut timeouts, arg2: *mut timeouts_it) -> *mut timeout; +} + // TODO: 宏定义 TIMEOUTS_FOREACH // B O N U S W H E E L I N T E R F A C E S |
