From 1705167ceb98d307de692e391f561db43a73dad2 Mon Sep 17 00:00:00 2001 From: Yuuki Takano Date: Tue, 24 Dec 2024 15:06:52 +0900 Subject: [PATCH] fix: use awkernel_sync for Mutex and RwLock To port to Awkernel, this PR uses awkernel_sync for Mutex and RwLock. Additionally, `awkernel_x86` and `awkernel_aarch64` features are added. Signed-off-by: Yuuki Takano --- Cargo.lock | 371 +++++++++++++++++++++++++++++++- Cargo.toml | 7 +- src/dds/datareader.rs | 6 +- src/dds/participant.rs | 136 ++++-------- src/dds/publisher.rs | 31 +-- src/dds/subscriber.rs | 24 +-- src/discovery/discovery_db.rs | 8 +- src/discovery/structure/data.rs | 3 +- src/message/message_receiver.rs | 2 +- src/rtps/reader.rs | 4 +- src/rtps/writer.rs | 28 +-- src/structure/proxy.rs | 7 +- 12 files changed, 441 insertions(+), 186 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 132b7fa..2bda72a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,15 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] [[package]] name = "android-tzdata" @@ -72,12 +81,34 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "awkernel_sync" +version = "0.1.0" +source = "git+https://github.com/tier4/awkernel_sync.git#3d64d9991028db0fd21324511428958d468d6ece" +dependencies = [ + "loom", + "parking_lot", + "x86_64", +] + +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "bumpalo" version = "3.16.0" @@ -230,7 +261,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fuchsia-zircon-sys", ] @@ -240,6 +271,19 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +[[package]] +name = "generator" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bd114ceda131d3b1d665eba35788690ad37f5916457286b32ab6fd3c438dd" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "log", + "rustversion", + "windows", +] + [[package]] name = "heck" version = "0.5.0" @@ -257,7 +301,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -331,12 +375,50 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "loom" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" +dependencies = [ + "cfg-if 1.0.0", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + [[package]] name = "memoffset" version = "0.9.1" @@ -412,6 +494,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi 0.3.9", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -427,6 +519,41 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -460,6 +587,77 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "redox_syscall" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.209" @@ -491,6 +689,15 @@ dependencies = [ "syn", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -506,6 +713,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "socket2" version = "0.5.7" @@ -519,7 +732,7 @@ dependencies = [ [[package]] name = "speedy" version = "0.8.7" -source = "git+https://github.com/ytakano/speedy.git#509f7ea1e08c3c4722da83fa0a36820d5aeaa0da" +source = "git+https://github.com/koute/speedy#df80ac3f851db61d915eb759fa47dfe6b6a8c126" dependencies = [ "memoffset", "speedy-derive", @@ -528,7 +741,7 @@ dependencies = [ [[package]] name = "speedy-derive" version = "0.8.7" -source = "git+https://github.com/ytakano/speedy.git#509f7ea1e08c3c4722da83fa0a36820d5aeaa0da" +source = "git+https://github.com/koute/speedy#df80ac3f851db61d915eb759fa47dfe6b6a8c126" dependencies = [ "proc-macro2", "quote", @@ -572,10 +785,70 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "umberdds" version = "0.1.0" dependencies = [ + "awkernel_sync", "byteorder", "bytes", "cdr", @@ -609,6 +882,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "volatile" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -704,6 +989,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -713,6 +1008,60 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -861,3 +1210,15 @@ dependencies = [ "winapi 0.2.8", "winapi-build", ] + +[[package]] +name = "x86_64" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae" +dependencies = [ + "bit_field", + "bitflags 2.6.0", + "rustversion", + "volatile", +] diff --git a/Cargo.toml b/Cargo.toml index d701fe6..7b3e184 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ mio-extras = "2.0.6" rand = { version = "0.8", default-features = false, features = ["small_rng"] } serde = { version = "1.0", default-features = false, features = ["derive"] } socket2 = "0.5" -speedy = { git = "https://github.com/ytakano/speedy.git", default-features = false, features = [ +speedy = { git = "https://github.com/koute/speedy", default-features = false, features = [ "speedy-derive", "alloc", ] } @@ -35,6 +35,7 @@ cdr = "0.2.4" chrono = { version = "0.4", optional = true } thiserror = "1.0" serde_repr = "0.1.18" +awkernel_sync = { git = "https://github.com/tier4/awkernel_sync.git" } [dev-dependencies] clap = { version = "4.5", features = ["derive"] } @@ -43,4 +44,6 @@ serde_derive = "1" [features] default = ["std"] -std = ["dep:chrono"] +std = ["dep:chrono", "awkernel_sync/std"] +awkernel_x86 = ["awkernel_sync/x86"] +awkernel_aarch64 = ["awkernel_sync/aarch64"] diff --git a/src/dds/datareader.rs b/src/dds/datareader.rs index 3701ab0..a298329 100644 --- a/src/dds/datareader.rs +++ b/src/dds/datareader.rs @@ -2,12 +2,12 @@ use crate::dds::{qos::DataReaderQosPolicies, subscriber::Subscriber, topic::Topi use crate::discovery::structure::cdr::deserialize; use crate::rtps::{cache::HistoryCache, reader::DataReaderStatusChanged}; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use core::marker::PhantomData; use mio_extras::channel as mio_channel; use mio_v06::{event::Evented, Poll, PollOpt, Ready, Token}; use serde::Deserialize; use std::io; -use std::sync::RwLock; /// DDS DataReader pub struct DataReader Deserialize<'de>> { @@ -47,7 +47,7 @@ impl Deserialize<'de>> DataReader { } fn get_data(&self) -> Vec { - let mut hc = self.rhc.write().expect("couldn't read ReaderHistoryCache"); + let mut hc = self.rhc.write(); let changes = hc.get_alive_changes(); for c in changes.iter() { hc.remove_change(c); @@ -62,7 +62,7 @@ impl Deserialize<'de>> DataReader { v } fn _remove_changes(&self) { - let mut hc = self.rhc.write().expect("couldn't write ReaderHistoryCache"); + let mut hc = self.rhc.write(); hc.remove_notalive_changes(); } pub fn get_qos(&self) -> DataReaderQosPolicies { diff --git a/src/dds/participant.rs b/src/dds/participant.rs index 50ae880..80ce3a8 100644 --- a/src/dds/participant.rs +++ b/src/dds/participant.rs @@ -30,9 +30,10 @@ use core::sync::atomic::{AtomicU32, Ordering}; use mio_extras::channel as mio_channel; use mio_v06::net::UdpSocket; use rand::rngs::SmallRng; -use std::sync::{Mutex, RwLock}; use std::thread::{self, Builder}; +use awkernel_sync::{mcs::MCSNode, mutex::Mutex, rwlock::RwLock}; + /// DDS DomainParticipant /// /// factory for the Publisher, Subscriber and Topic. @@ -43,10 +44,8 @@ pub struct DomainParticipant { impl RTPSEntity for DomainParticipant { fn guid(&self) -> GUID { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .guid() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).guid() } } @@ -91,15 +90,15 @@ impl DomainParticipant { dp } pub fn create_publisher(&self, qos: PublisherQos) -> Publisher { + let mut node = MCSNode::new(); self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") + .lock(&mut node) .create_publisher(self.clone(), qos) } pub fn create_subscriber(&self, qos: SubscriberQos) -> Subscriber { + let mut node = MCSNode::new(); self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") + .lock(&mut node) .create_subscriber(self.clone(), qos) } pub fn create_topic( @@ -109,64 +108,46 @@ impl DomainParticipant { kind: TopicKind, qos: TopicQos, ) -> Topic { + let mut node = MCSNode::new(); self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") + .lock(&mut node) .create_topic(self.clone(), name, type_desc, kind, qos) } pub fn domain_id(&self) -> u16 { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .domain_id() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).domain_id() } pub fn participant_id(&self) -> u16 { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .participant_id() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).participant_id() } pub(crate) fn gen_entity_key(&self) -> [u8; 3] { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .gen_entity_key() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).gen_entity_key() } pub fn get_default_publisher_qos(&self) -> PublisherQosPolicies { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .get_default_publisher_qos() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).get_default_publisher_qos() } pub fn set_default_publisher_qos(&mut self, qos: PublisherQosPolicies) { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .set_default_publisher_qos(qos); + let mut node = MCSNode::new(); + self.inner.lock(&mut node).set_default_publisher_qos(qos); } pub fn get_default_subscriber_qos(&self) -> SubscriberQosPolicies { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .get_default_subscriber_qos() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).get_default_subscriber_qos() } pub fn set_default_subscriber_qos(&mut self, qos: SubscriberQosPolicies) { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .set_default_subscriber_qos(qos); + let mut node = MCSNode::new(); + self.inner.lock(&mut node).set_default_subscriber_qos(qos); } pub fn get_default_topic_qos(&self) -> TopicQosPolicies { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .get_default_topic_qos() + let mut node = MCSNode::new(); + self.inner.lock(&mut node).get_default_topic_qos() } pub fn set_default_topic_qos(&mut self, qos: TopicQosPolicies) { - self.inner - .lock() - .expect("couldn't lock DomainParticipantDisc") - .set_default_topic_qos(qos); + let mut node = MCSNode::new(); + self.inner.lock(&mut node).set_default_topic_qos(qos); } } @@ -198,16 +179,10 @@ impl DomainParticipantDisc { } } pub fn create_publisher(&self, dp: DomainParticipant, qos: PublisherQos) -> Publisher { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .create_publisher(dp, qos) + self.inner.read().create_publisher(dp, qos) } pub fn create_subscriber(&self, dp: DomainParticipant, qos: SubscriberQos) -> Subscriber { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .create_subscriber(dp, qos) + self.inner.read().create_subscriber(dp, qos) } pub fn create_topic( &self, @@ -219,62 +194,34 @@ impl DomainParticipantDisc { ) -> Topic { self.inner .read() - .expect("couldn't read lock DomainParticipantInnet") .create_topic(dp, name, type_desc, kind, qos) } pub fn domain_id(&self) -> u16 { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .domain_id + self.inner.read().domain_id } pub fn participant_id(&self) -> u16 { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .participant_id + self.inner.read().participant_id } pub fn gen_entity_key(&self) -> [u8; 3] { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .gen_entity_key() + self.inner.read().gen_entity_key() } pub fn get_default_publisher_qos(&self) -> PublisherQosPolicies { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .get_default_publisher_qos() + self.inner.read().get_default_publisher_qos() } pub fn set_default_publisher_qos(&mut self, qos: PublisherQosPolicies) { - self.inner - .write() - .expect("couldn't write lock DomainParticipantInnet") - .set_default_publisher_qos(qos); + self.inner.write().set_default_publisher_qos(qos); } pub fn get_default_subscriber_qos(&self) -> SubscriberQosPolicies { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .get_default_subscriber_qos() + self.inner.read().get_default_subscriber_qos() } pub fn set_default_subscriber_qos(&mut self, qos: SubscriberQosPolicies) { - self.inner - .write() - .expect("couldn't write lock DomainParticipantInnet") - .set_default_subscriber_qos(qos); + self.inner.write().set_default_subscriber_qos(qos); } pub fn get_default_topic_qos(&self) -> TopicQosPolicies { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .get_default_topic_qos() + self.inner.read().get_default_topic_qos() } pub fn set_default_topic_qos(&mut self, qos: TopicQosPolicies) { - self.inner - .write() - .expect("couldn't write lock DomainParticipantInnet") - .set_default_topic_qos(qos); + self.inner.write().set_default_topic_qos(qos); } } impl Drop for DomainParticipantDisc { @@ -287,10 +234,7 @@ impl Drop for DomainParticipantDisc { impl RTPSEntity for DomainParticipantDisc { fn guid(&self) -> GUID { - self.inner - .read() - .expect("couldn't read lock DomainParticipantInnet") - .my_guid + self.inner.read().my_guid } } diff --git a/src/dds/publisher.rs b/src/dds/publisher.rs index 76b078c..9de5b87 100644 --- a/src/dds/publisher.rs +++ b/src/dds/publisher.rs @@ -10,8 +10,8 @@ use crate::network::net_util::{usertraffic_multicast_port, usertraffic_unicast_p use crate::rtps::writer::{DataWriterStatusChanged, WriterCmd, WriterIngredients}; use crate::structure::{Duration, EntityId, EntityKind, RTPSEntity, GUID}; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use mio_extras::channel as mio_channel; -use std::sync::RwLock; /// DDS Publisher /// @@ -60,7 +60,6 @@ impl Publisher { ) -> DataWriter { self.inner .read() - .expect("couldn't read lock InnerPublisher") .create_datawriter(qos, topic, self.clone()) } @@ -72,42 +71,24 @@ impl Publisher { ) -> DataWriter { self.inner .read() - .expect("couldn't read lock InnerPublisher") .create_datawriter_with_entityid(qos, topic, self.clone(), entity_id) } pub fn get_qos(&self) -> PublisherQosPolicies { - self.inner - .read() - .expect("couldn't read lock InnerPublisher") - .get_qos() + self.inner.read().get_qos() } pub fn set_qos(&mut self, qos: PublisherQosPolicies) { - self.inner - .write() - .expect("couldn't write lock InnerPublisher") - .set_qos(qos); + self.inner.write().set_qos(qos); } pub fn domain_participant(&self) -> DomainParticipant { - self.inner - .read() - .expect("couldn't read lock InnerPublisher") - .dp - .clone() + self.inner.read().dp.clone() } pub fn get_default_datawriter_qos(&self) -> DataWriterQosPolicies { - self.inner - .read() - .expect("couldn't read lock InnerPublisher") - .default_dw_qos - .clone() + self.inner.read().default_dw_qos.clone() } pub fn set_default_datawriter_qos(&mut self, qos: DataWriterQosPolicies) { - self.inner - .write() - .expect("couldn't write lock InnerPublisher") - .default_dw_qos = qos; + self.inner.write().default_dw_qos = qos; } } diff --git a/src/dds/subscriber.rs b/src/dds/subscriber.rs index 9ca2f86..3b9295b 100644 --- a/src/dds/subscriber.rs +++ b/src/dds/subscriber.rs @@ -12,9 +12,9 @@ use crate::rtps::{ }; use crate::structure::{Duration, EntityId, EntityKind, RTPSEntity, GUID}; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use mio_extras::channel as mio_channel; use serde::Deserialize; -use std::sync::RwLock; /// DDS Subscriber /// @@ -49,7 +49,6 @@ impl Subscriber { ) -> DataReader { self.inner .read() - .expect("couldn't read lock InnerSubscriber") .create_datareader(qos, topic, self.clone()) } pub fn create_datareader_with_entityid Deserialize<'de>>( @@ -60,33 +59,20 @@ impl Subscriber { ) -> DataReader { self.inner .read() - .expect("couldn't read lock InnerSubscriber") .create_datareader_with_entityid(qos, topic, self.clone(), entity_id) } pub fn get_qos(&self) -> SubscriberQosPolicies { - self.inner - .read() - .expect("couldn't read lock InnerSubscriber") - .get_qos() + self.inner.read().get_qos() } pub fn set_qos(&mut self, qos: SubscriberQosPolicies) { - self.inner - .write() - .expect("couldn't write lock InnerSubscriber") - .set_qos(qos) + self.inner.write().set_qos(qos) } pub fn get_default_datareader_qos(&self) -> DataReaderQosPolicies { - self.inner - .read() - .expect("couldn't read lock InnerSubscriber") - .get_default_datareader_qos() + self.inner.read().get_default_datareader_qos() } pub fn set_default_datareader_qos(&mut self, qos: DataReaderQosPolicies) { - self.inner - .write() - .expect("couldn't write lock InnerSubscriber") - .set_default_datareader_qos(qos) + self.inner.write().set_default_datareader_qos(qos) } } diff --git a/src/discovery/discovery_db.rs b/src/discovery/discovery_db.rs index 0e336d5..d4d7f89 100644 --- a/src/discovery/discovery_db.rs +++ b/src/discovery/discovery_db.rs @@ -3,7 +3,7 @@ use crate::message::submessage::element::Timestamp; use crate::structure::GuidPrefix; use alloc::collections::BTreeMap; use alloc::sync::Arc; -use std::sync::Mutex; +use awkernel_sync::{mcs::MCSNode, mutex::Mutex}; #[derive(Clone)] pub struct DiscoveryDB { @@ -22,12 +22,14 @@ impl DiscoveryDB { timestamp: Timestamp, data: SPDPdiscoveredParticipantData, ) { - let mut inner = self.inner.lock().expect("couldn't lock DiscoveryDBInner"); + let mut node = MCSNode::new(); + let mut inner = self.inner.lock(&mut node); inner.write(guid_prefix, timestamp, data) } pub fn read(&self, guid_prefix: GuidPrefix) -> Option { - let inner = self.inner.lock().expect("couldn't lock DiscoveryDBInner"); + let mut node = MCSNode::new(); + let inner = self.inner.lock(&mut node); inner.read(guid_prefix) } } diff --git a/src/discovery/structure/data.rs b/src/discovery/structure/data.rs index 912d383..aa37f22 100644 --- a/src/discovery/structure/data.rs +++ b/src/discovery/structure/data.rs @@ -4,12 +4,13 @@ use crate::message::message_header::ProtocolVersion; use crate::message::submessage::element::{Count, Locator}; use crate::rtps::cache::HistoryCache; use crate::structure::{Duration, ParameterId, ReaderProxy, VendorId, WriterProxy, GUID}; +use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use colored::*; use enumflags2::BitFlags; use serde::de::{self, Deserialize, Deserializer, SeqAccess, Visitor}; use serde::{ser::SerializeStruct, Serialize}; use std::fmt; -use std::sync::{Arc, RwLock}; #[allow(dead_code)] #[derive(Clone, Default)] diff --git a/src/message/message_receiver.rs b/src/message/message_receiver.rs index 6cbbb36..61c55d3 100644 --- a/src/message/message_receiver.rs +++ b/src/message/message_receiver.rs @@ -15,9 +15,9 @@ use crate::structure::{EntityId, GuidPrefix, VendorId, GUID}; use alloc::collections::BTreeMap; use alloc::fmt; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use colored::*; use std::error; -use std::sync::RwLock; #[derive(Debug, Clone)] struct MessageError(String); diff --git a/src/rtps/reader.rs b/src/rtps/reader.rs index 94232bd..2a16a4f 100644 --- a/src/rtps/reader.rs +++ b/src/rtps/reader.rs @@ -16,13 +16,13 @@ use crate::structure::{ use alloc::collections::BTreeMap; use alloc::rc::Rc; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use colored::*; use core::net::Ipv4Addr; use core::time::Duration as StdDuration; use enumflags2::BitFlags; use mio_extras::channel as mio_channel; use speedy::{Endianness, Writable}; -use std::sync::RwLock; /// RTPS StatefulReader pub struct Reader { @@ -127,7 +127,6 @@ impl Reader { if self .reader_cache .write() - .expect("couldn't write reader_cache") .add_change(change.clone()) .is_err() { @@ -160,7 +159,6 @@ impl Reader { if self .reader_cache .write() - .expect("couldn't write reader_cache") .add_change(change.clone()) .is_err() { diff --git a/src/rtps/writer.rs b/src/rtps/writer.rs index 4764a5d..4b8df2f 100644 --- a/src/rtps/writer.rs +++ b/src/rtps/writer.rs @@ -18,13 +18,13 @@ use crate::structure::{Duration, EntityId, RTPSEntity, ReaderProxy, TopicKind, W use alloc::collections::BTreeMap; use alloc::rc::Rc; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use colored::*; use core::net::Ipv4Addr; use core::time::Duration as CoreDuration; use mio_extras::channel as mio_channel; use mio_v06::Token; use speedy::{Endianness, Writable}; -use std::sync::RwLock; /// RTPS StatefulWriter pub struct Writer { @@ -152,14 +152,7 @@ impl Writer { pub fn unsent_changes_reset(&mut self) { // StatelessWriter for rl in &mut self.reader_locators { - rl.unsent_changes = self - .writer_cache - .read() - .expect("couldn't read writer_cache") - .changes - .values() - .cloned() - .collect(); + rl.unsent_changes = self.writer_cache.read().changes.values().cloned().collect(); } } @@ -222,7 +215,6 @@ impl Writer { if let Some(aa_change) = self .writer_cache .read() - .expect("couldn't read writer_cache") .get_change(self.guid, change_for_reader.seq_num) { // build RTPS Message @@ -352,10 +344,7 @@ impl Writer { pub fn send_heart_beat(&mut self) { let time_stamp = Timestamp::now(); - let writer_cache = self - .writer_cache - .read() - .expect("couldn't read writer_cache"); + let writer_cache = self.writer_cache.read(); self.hb_counter += 1; let self_guid_prefix = self.guid_prefix(); let self_entity_id = self.entity_id(); @@ -421,10 +410,7 @@ impl Writer { fn add_change_to_hc(&mut self, change: CacheChange) -> Result<(), ()> { // add change to WriterHistoryCache & set status to Unset on each ReaderProxy - self.writer_cache - .write() - .expect("couldn't write writer_cache") - .add_change(change)?; + self.writer_cache.write().add_change(change)?; for reader_proxy in self.matched_readers.values_mut() { reader_proxy.update_cache_state( self.last_change_sequence_number, @@ -493,7 +479,6 @@ impl Writer { if let Some(aa_change) = self .writer_cache .read() - .expect("couldn't read writer_cache") .get_change(self.guid, change.seq_num) { // build RTPS Message @@ -558,10 +543,7 @@ impl Writer { // send Heartbeat because, the sample is no longer avilable self.hb_counter += 1; let time_stamp = Timestamp::now(); - let writer_cache = self - .writer_cache - .read() - .expect("couldn't read writer_cache"); + let writer_cache = self.writer_cache.read(); let mut message_builder = MessageBuilder::new(); message_builder.info_ts(Endianness::LittleEndian, time_stamp); message_builder.heartbeat( diff --git a/src/structure/proxy.rs b/src/structure/proxy.rs index 9c1c09e..b370f4f 100644 --- a/src/structure/proxy.rs +++ b/src/structure/proxy.rs @@ -7,9 +7,9 @@ use crate::rtps::cache::{ use crate::structure::{guid::GUID, parameter_id::ParameterId}; use alloc::collections::BTreeMap; use alloc::sync::Arc; +use awkernel_sync::rwlock::RwLock; use core::cmp::{max, min}; use serde::{ser::SerializeStruct, Serialize}; -use std::sync::RwLock; #[derive(Clone)] pub struct ReaderProxy { @@ -56,10 +56,7 @@ impl ReaderProxy { } pub fn acked_changes_set(&mut self, commited_seq_num: SequenceNumber) { - let hc = self - .history_cache - .read() - .expect("couldn't read history_cache"); + let hc = self.history_cache.read(); for (k, v) in &hc.changes { if v.sequence_number <= commited_seq_num { self.cache_state.insert(