-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26e0ac5
commit 0c1e385
Showing
22 changed files
with
1,148 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,12 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
pub mod allocated_descriptor; | ||
pub mod chunk_header; | ||
pub mod descriptor; | ||
pub mod segment; | ||
pub mod storage; | ||
pub mod subscription; | ||
|
||
tested_crate_module!(storage); | ||
tested_crate_module!(subscription); | ||
|
||
pub(crate) mod allocated_descriptor; | ||
pub(crate) mod chunk_header; | ||
|
||
mod segment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
pub mod array; | ||
pub mod segment; | ||
tested_crate_module!(array); | ||
tested_crate_module!(segment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use std::fmt::Display; | ||
use std::fmt::{Debug, Display}; | ||
|
||
use rand::Rng; | ||
use shared_memory::{Shmem, ShmemConf, ShmemError}; | ||
|
@@ -26,6 +26,18 @@ pub struct Segment<ID> { | |
pub id: ID, | ||
} | ||
|
||
impl<ID> Debug for Segment<ID> | ||
where | ||
ID: Debug, | ||
{ | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Segment") | ||
.field("shmem", &self.shmem.as_ptr()) | ||
.field("id", &self.id) | ||
.finish() | ||
} | ||
} | ||
|
||
impl<ID> Segment<ID> | ||
where | ||
rand::distributions::Standard: rand::distributions::Distribution<ID>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use zenoh_result::ZResult; | ||
|
||
pub const TEST_SEGMENT_PREFIX: &str = "test"; | ||
|
||
pub fn validate_memory(mem1: &mut [u8], mem2: &[u8]) { | ||
assert!(mem1.len() == mem2.len()); | ||
for cycle in 0..255u8 { | ||
// sequentially fill segment1 with values checking segment2 having these changes | ||
for i in 0..mem1.len() { | ||
mem1[i] = cycle; | ||
assert!(mem2[i] == cycle); | ||
} | ||
|
||
// check the whole segment2 having proper values | ||
for i in mem2 { | ||
assert!(*i == cycle); | ||
} | ||
} | ||
} | ||
|
||
pub fn execute_concurrent<TaskFun>(concurrent_tasks: usize, iterations: usize, task_fun: TaskFun) | ||
where | ||
TaskFun: Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static, | ||
{ | ||
let mut tasks = vec![]; | ||
for task_index in 0..concurrent_tasks { | ||
let c_task_fun = task_fun.clone(); | ||
let task_handle = std::thread::spawn(move || { | ||
for iteration in 0..iterations { | ||
if let Err(e) = c_task_fun(task_index, iteration) { | ||
panic!("task {task_index}: iteration {iteration}: {e}") | ||
} | ||
} | ||
}); | ||
tasks.push(task_handle); | ||
} | ||
for task in tasks { | ||
task.join().expect("Error joining thread!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use super::{descriptor::OwnedDescriptor, storage::GLOBAL_STORAGE, validator::GLOBAL_VALIDATOR}; | ||
|
||
#[derive(Debug)] | ||
pub struct AllocatedWatchdog { | ||
pub descriptor: OwnedDescriptor, | ||
} | ||
|
||
impl AllocatedWatchdog { | ||
pub(crate) fn new(descriptor: OwnedDescriptor) -> Self { | ||
// reset descriptor on allocation | ||
descriptor.validate(); | ||
Self { descriptor } | ||
} | ||
} | ||
|
||
impl Drop for AllocatedWatchdog { | ||
fn drop(&mut self) { | ||
GLOBAL_VALIDATOR.remove(self.descriptor.clone()); | ||
GLOBAL_STORAGE.free_watchdog(self.descriptor.clone()); | ||
} | ||
} |
Oops, something went wrong.