Skip to content

Commit

Permalink
Improve shared rti accesses by replacing mutex with RwLock
Browse files Browse the repository at this point in the history
- Multiple read accesses without any write access are now possible
  and only one write access is allowed for shared rti variables.
  • Loading branch information
chanijjani committed Feb 18, 2024
1 parent 7ba3d49 commit 81df66d
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 240 deletions.
32 changes: 17 additions & 15 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
# build:
# runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cd rust/rti; cargo build --verbose
# steps:
# - uses: actions/checkout@v3
# - name: Build
# run: cd rust/rti; cargo build --verbose

# unit-tests:
# runs-on: ubuntu-latest

unit-tests:
# steps:
# - uses: actions/checkout@v3
# - name: Unit tests
# run: cd rust/rti; cargo test

fetch-rust-rti:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Unit tests
run: cd rust/rti; cargo test

# fetch-lf:
# uses: chanijjani/lingua-franca/.github/workflows/extract-ref.yml@master
# with:
# file: 'lingua-franca-ref.txt'

lf-default:
lf-rust-rti:
needs: fetch-rust-rti
# TODO(chanijjani): Change the pointer to point to the main lingua-franca repo.
uses: chanijjani/lingua-franca/.github/workflows/c-tests-with-rust-rti.yml@integration_tests_with_rust_rti
4 changes: 2 additions & 2 deletions rust/rti/src/federate_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ impl FederateInfo {
}
}

pub fn e(&self) -> &SchedulingNode {
pub fn enclave(&self) -> &SchedulingNode {
&self.enclave
}

pub fn enclave(&mut self) -> &mut SchedulingNode {
pub fn enclave_mut(&mut self) -> &mut SchedulingNode {
&mut self.enclave
}

Expand Down
8 changes: 4 additions & 4 deletions rust/rti/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn process_args(rti: &mut RTIRemote, argv: &[String]) -> Result<(), &'static
return Err("Fail to parse a string to i64");
}
};
rti.base()
rti.base_mut()
.set_number_of_scheduling_nodes(num_federates.try_into().unwrap()); // FIXME: panic if the converted value doesn't fit
println!(
"RTI: Number of federates: {}",
Expand Down Expand Up @@ -176,13 +176,13 @@ pub fn initialize_federates(rti: &mut RTIRemote) {
let mut federate = FederateInfo::new();
// FIXME: Handle "as u16" properly.
initialize_federate(&mut federate, i as u16);
let scheduling_nodes: &mut Vec<FederateInfo> = rti.base().scheduling_nodes();
let scheduling_nodes: &mut Vec<FederateInfo> = rti.base_mut().scheduling_nodes_mut();
scheduling_nodes.insert(i as usize, federate);
}
}

fn initialize_federate(fed: &mut FederateInfo, id: u16) {
let enclave = fed.enclave();
let enclave = fed.enclave_mut();
enclave.initialize_scheduling_node(id);
// TODO: fed.set_in_transit_message_tags();
// TODO: fed.set_server_ip_addr();
Expand Down Expand Up @@ -213,5 +213,5 @@ pub fn start_rti_server(_f_rti: &mut RTIRemote) -> Result<Server, Box<dyn Error>
* Initialize the _RTI instance.
*/
pub fn initialize_rti() -> RTIRemote {
RTIRemote::new()
RTIRemote::new(
}
Loading

0 comments on commit 81df66d

Please sign in to comment.