From 4c647b5fb5be063b06e07c420ccb7de93c0b6082 Mon Sep 17 00:00:00 2001 From: playX18 Date: Tue, 1 Oct 2024 12:18:36 +0700 Subject: [PATCH] refactor(gstd): use waker-fn instead of unsafe code --- Cargo.lock | 5 +++-- gstd/Cargo.toml | 1 + gstd/src/async_runtime/waker.rs | 16 ++-------------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edcefd2611e..9103b72a56b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7471,6 +7471,7 @@ dependencies = [ "hex", "parity-scale-codec", "scale-info", + "waker-fn", ] [[package]] @@ -19026,9 +19027,9 @@ dependencies = [ [[package]] name = "waker-fn" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" [[package]] name = "walkdir" diff --git a/gstd/Cargo.toml b/gstd/Cargo.toml index 46e61e53c68..5882831aacc 100644 --- a/gstd/Cargo.toml +++ b/gstd/Cargo.toml @@ -25,6 +25,7 @@ hex = { workspace = true, features = ["alloc"] } parity-scale-codec = { workspace = true, features = ["derive"] } scale-info = { workspace = true, features = ["derive"] } futures = { workspace = true, features = ["alloc"] } +waker-fn = "1.1.1" [features] #! ## Default features diff --git a/gstd/src/async_runtime/waker.rs b/gstd/src/async_runtime/waker.rs index e16f56c908b..e24abc9b624 100644 --- a/gstd/src/async_runtime/waker.rs +++ b/gstd/src/async_runtime/waker.rs @@ -18,20 +18,8 @@ //! Module for Gear programs asynchronous waker. -use core::{ - ptr, - task::{RawWaker, RawWakerVTable, Waker}, -}; - -const VTABLE: RawWakerVTable = RawWakerVTable::new(clone_waker, wake, wake_by_ref, drop_waker); +use core::task::Waker; pub(crate) fn empty() -> Waker { - unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &VTABLE)) } -} - -unsafe fn clone_waker(ptr: *const ()) -> RawWaker { - RawWaker::new(ptr, &VTABLE) + waker_fn::waker_fn(|| {}) } -unsafe fn wake(_ptr: *const ()) {} -unsafe fn wake_by_ref(_ptr: *const ()) {} -unsafe fn drop_waker(_ptr: *const ()) {}