-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from elfenpiff/iox2-31-solve-circular-dependency
[#31] Solve circular dependency
- Loading branch information
Showing
14 changed files
with
191 additions
and
81 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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache Software License 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license | ||
// which is available at https://opensource.org/licenses/MIT. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use crate::{allocator::BaseAllocator, math::align}; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
/// Simple BumpAllocator for testing purposes. Do not use this in production. If you are looking | ||
/// for a production ready BumpAllocator use the one from iceoryx2_bb_memory::bump_allocator | ||
#[doc(hidden)] | ||
pub struct BumpAllocator { | ||
start: usize, | ||
pos: AtomicUsize, | ||
} | ||
|
||
impl BumpAllocator { | ||
pub fn new(start: usize) -> Self { | ||
Self { | ||
start, | ||
pos: AtomicUsize::new(start), | ||
} | ||
} | ||
} | ||
|
||
impl BaseAllocator for BumpAllocator { | ||
fn allocate( | ||
&self, | ||
layout: std::alloc::Layout, | ||
) -> Result<std::ptr::NonNull<[u8]>, crate::allocator::AllocationError> { | ||
let mem = align(self.pos.load(Ordering::Relaxed), layout.align()); | ||
self.pos.store(mem + layout.size(), Ordering::Relaxed); | ||
|
||
unsafe { | ||
Ok(std::ptr::NonNull::new_unchecked( | ||
std::slice::from_raw_parts_mut(mem as *mut u8, layout.size()), | ||
)) | ||
} | ||
} | ||
|
||
unsafe fn deallocate( | ||
&self, | ||
_ptr: std::ptr::NonNull<u8>, | ||
_layout: std::alloc::Layout, | ||
) -> Result<(), crate::allocator::DeallocationError> { | ||
self.pos.store(self.start, Ordering::Relaxed); | ||
Ok(()) | ||
} | ||
} |
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
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
Oops, something went wrong.