summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzy <[email protected]>2023-09-15 02:48:21 +0000
committerzy <[email protected]>2023-09-15 02:48:21 +0000
commite4b4b7bc35fc394ab62c9bd81c754689c771a42f (patch)
treed1881b9af67b295572d50df86f3c03b114e57650
parent586d03d6a04fc269d3ddf5058a163bd3562d148c (diff)
移除 `#[link(name = "timeout")]` 声明,提前到 build.rs 中.
补充缺失的 struct 定义
-rw-r--r--src/timeout.rs57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/timeout.rs b/src/timeout.rs
index 297635b..0dc58e4 100644
--- a/src/timeout.rs
+++ b/src/timeout.rs
@@ -1,6 +1,6 @@
use std::ptr::null_mut;
-use libc::{c_char, c_int, c_uint, c_void, FILE};
+use libc::{c_char, c_int, c_uint, c_void, FILE, c_ulonglong};
// TODO 检查条件编译选项
// 目前暂时全部注释掉
@@ -12,7 +12,7 @@ pub const TIMEOUT_V_REL: u32 = 538313254;
pub const TIMEOUT_V_ABI: u32 = 538313252;
pub const TIMEOUT_V_API: u32 = 538313254;
-#[link(name = "timeout")]
+
extern "C" {
pub fn timeout_version() -> c_int;
pub fn timeout_vendor() -> *const c_char;
@@ -32,7 +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_t = c_ulonglong;
pub type timeout_error_t = usize;
/// C A L L B A C K I N T E R F A C E
@@ -56,12 +56,6 @@ pub const TIMEOUT_ABS: i32 = 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)]
@@ -105,13 +99,13 @@ impl Default for timeout {
}
}
-#[link(name = "timeout")]
+
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)]
-#[link(name = "timeout")]
+
extern "C" {
/* true if on timing wheel, false otherwise */
pub fn timeout_pending(arg1: *mut timeout) -> bool;
@@ -123,13 +117,29 @@ extern "C" {
/// T I M I N G W H E E L I N T E R F A C E S
+// 原定义在 timeout.c line 206 | TAILQ_HEAD(timeout_list, timeout);
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct timeout_list {
+ pub tqh_first: *mut timeout,
+ pub tqh_last: *mut *mut timeout,
+}
+
+// for timeouts
+const WHEEL_LEN: usize = 64; // timeout.c line 132 | (1U << WHEEL_BIT ) ,WHEEL_BIT = 6
+const WHEEL_NUM: usize = 4;
+pub type wheel_t = u64;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct timeouts {
- _unused: [u8; 0],
+ pub wheel: [[timeout_list; WHEEL_LEN]; WHEEL_NUM],
+ pub expired: timeout_list,
+ pub pending: [wheel_t; WHEEL_NUM],
+ pub curtime: timeout_t,
+ pub hertz: timeout_t,
}
-#[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 timeout_error_t) -> *mut timeouts;
@@ -157,11 +167,11 @@ extern "C" {
// TODO check FILE type
pub fn timeouts_check(arg1: *mut timeouts, arg2: *mut FILE) -> bool;
}
+
extern "C" {
pub static mut stderr: *mut FILE;
}
-
pub const TIMEOUTS_PENDING: i32 = 16;
pub const TIMEOUTS_EXPIRED: i32 = 32;
pub const TIMEOUTS_ALL: i32 = 48;
@@ -214,11 +224,28 @@ impl Default for timeouts_it {
* 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")]
+// #[link(name = "timeout")]
extern "C" {
pub fn timeouts_next(arg1: *mut timeouts, arg2: *mut timeouts_it) -> *mut timeout;
}
+/*
+ * Calculate the interval our caller can wait before needing to process
+ * events.
+ */
+
+// extern "C" {
+// pub fn timeouts_int(T: *mut timeouts) -> timeout_t;
+// }
+// pub fn timeouts_timeout(t: *mut timeouts) -> timeout_t {
+// unsafe {
+// if !((*t).expired.tqh_first.is_null()) {
+// return 0;
+// }
+// timeouts_int(t)
+// }
+// }
+
// TODO: 宏定义 TIMEOUTS_FOREACH
// B O N U S W H E E L I N T E R F A C E S