about summary refs log tree commit diff
path: root/library/std/src/sys/itron
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2023-02-16 11:40:19 +0530
committerGitHub <noreply@github.com>2023-02-16 11:40:19 +0530
commit0c5bbca12da926e927c74665fe6abac59bbb49b8 (patch)
tree2f0328d32ceee401b9c37c4581c51cf6289cd0d5 /library/std/src/sys/itron
parentdc7a676778706bde3b50ff6d4fe81e2955bd4847 (diff)
parent78245286dcde9f2cf99a370ec0cd4383fa684404 (diff)
downloadrust-0c5bbca12da926e927c74665fe6abac59bbb49b8.tar.gz
rust-0c5bbca12da926e927c74665fe6abac59bbb49b8.zip
Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-se
Use id-based thread parking on SOLID

By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX.

ping ``@kawadakk``
r? ``@m-ou-se``
``@rustbot`` label +T-libs
Diffstat (limited to 'library/std/src/sys/itron')
-rw-r--r--library/std/src/sys/itron/thread_parking.rs37
-rw-r--r--library/std/src/sys/itron/wait_flag.rs72
2 files changed, 37 insertions, 72 deletions
diff --git a/library/std/src/sys/itron/thread_parking.rs b/library/std/src/sys/itron/thread_parking.rs
new file mode 100644
index 00000000000..fe9934439d1
--- /dev/null
+++ b/library/std/src/sys/itron/thread_parking.rs
@@ -0,0 +1,37 @@
+use super::abi;
+use super::error::expect_success_aborting;
+use super::time::with_tmos;
+use crate::time::Duration;
+
+pub type ThreadId = abi::ID;
+
+pub use super::task::current_task_id_aborting as current;
+
+pub fn park(_hint: usize) {
+    match unsafe { abi::slp_tsk() } {
+        abi::E_OK | abi::E_RLWAI => {}
+        err => {
+            expect_success_aborting(err, &"slp_tsk");
+        }
+    }
+}
+
+pub fn park_timeout(dur: Duration, _hint: usize) {
+    match with_tmos(dur, |tmo| unsafe { abi::tslp_tsk(tmo) }) {
+        abi::E_OK | abi::E_RLWAI | abi::E_TMOUT => {}
+        err => {
+            expect_success_aborting(err, &"tslp_tsk");
+        }
+    }
+}
+
+pub fn unpark(id: ThreadId, _hint: usize) {
+    match unsafe { abi::wup_tsk(id) } {
+        // It is allowed to try to wake up a destroyed or unrelated task, so we ignore all
+        // errors that could result from that situation.
+        abi::E_OK | abi::E_NOEXS | abi::E_OBJ | abi::E_QOVR => {}
+        err => {
+            expect_success_aborting(err, &"wup_tsk");
+        }
+    }
+}
diff --git a/library/std/src/sys/itron/wait_flag.rs b/library/std/src/sys/itron/wait_flag.rs
deleted file mode 100644
index e432edd2077..00000000000
--- a/library/std/src/sys/itron/wait_flag.rs
+++ /dev/null
@@ -1,72 +0,0 @@
-use crate::mem::MaybeUninit;
-use crate::time::Duration;
-
-use super::{
-    abi,
-    error::{expect_success, fail},
-    time::with_tmos,
-};
-
-const CLEAR: abi::FLGPTN = 0;
-const RAISED: abi::FLGPTN = 1;
-
-/// A thread parking primitive that is not susceptible to race conditions,
-/// but provides no atomic ordering guarantees and allows only one `raise` per wait.
-pub struct WaitFlag {
-    flag: abi::ID,
-}
-
-impl WaitFlag {
-    /// Creates a new wait flag.
-    pub fn new() -> WaitFlag {
-        let flag = expect_success(
-            unsafe {
-                abi::acre_flg(&abi::T_CFLG {
-                    flgatr: abi::TA_FIFO | abi::TA_WSGL | abi::TA_CLR,
-                    iflgptn: CLEAR,
-                })
-            },
-            &"acre_flg",
-        );
-
-        WaitFlag { flag }
-    }
-
-    /// Wait for the wait flag to be raised.
-    pub fn wait(&self) {
-        let mut token = MaybeUninit::uninit();
-        expect_success(
-            unsafe { abi::wai_flg(self.flag, RAISED, abi::TWF_ORW, token.as_mut_ptr()) },
-            &"wai_flg",
-        );
-    }
-
-    /// Wait for the wait flag to be raised or the timeout to occur.
-    ///
-    /// Returns whether the flag was raised (`true`) or the operation timed out (`false`).
-    pub fn wait_timeout(&self, dur: Duration) -> bool {
-        let mut token = MaybeUninit::uninit();
-        let res = with_tmos(dur, |tmout| unsafe {
-            abi::twai_flg(self.flag, RAISED, abi::TWF_ORW, token.as_mut_ptr(), tmout)
-        });
-
-        match res {
-            abi::E_OK => true,
-            abi::E_TMOUT => false,
-            error => fail(error, &"twai_flg"),
-        }
-    }
-
-    /// Raise the wait flag.
-    ///
-    /// Calls to this function should be balanced with the number of successful waits.
-    pub fn raise(&self) {
-        expect_success(unsafe { abi::set_flg(self.flag, RAISED) }, &"set_flg");
-    }
-}
-
-impl Drop for WaitFlag {
-    fn drop(&mut self) {
-        expect_success(unsafe { abi::del_flg(self.flag) }, &"del_flg");
-    }
-}