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 6049a65
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 243 deletions.
65 changes: 46 additions & 19 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,60 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# branches: [ "main" ]

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

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

unit-tests:
# fetch-rust-rti:
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3

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

runs-on: ubuntu-latest
timeout-minutes: 30

steps:
# - name: Check out the current PR
- 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:
# 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
- name: Check out lingua-franca repository
uses: actions/checkout@v3
with:
# TODO: Change the below repo into 'lf-lang/lingua-franca'
# after this PR is merged to lf-lang/lingua-franca@master.
repository: chanijjani/lingua-franca
submodules: true
fetch-depth: 0
ref: integration_tests_with_rust_rti
# - name: Prepare build environment
# uses: chanijjani/lingua-franca/.github/actions/prepare-build-env@integration_tests_with_rust_rti
- name: Perform federated tests for C target with Rust RTI
# TODO: Drop "git checkout" after this PR is merged to lf-lang/lingua-franca@master.
run:
# git clone https://github.com/chanijjani/lingua-franca.git;
# cd lingua-franca;
# git checkout integration_tests_with_rust_rti;
./gradlew targetTest -Ptarget=RustRti
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
6 changes: 3 additions & 3 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
Loading

0 comments on commit 6049a65

Please sign in to comment.