Skip to content

Commit

Permalink
Allocator implementation ordeR
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Oct 30, 2019
1 parent a748b8c commit c9bc705
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
36 changes: 18 additions & 18 deletions bastion-executor/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static GLOBAL: GlobalThreadAndCoroutineSwitchableAllocatorInstance =
///
/// It is this piece of logic that necessitates this macro definition.
#[thread_local]
static mut per_thread_state: PerThreadState<
static mut PER_THREAD_STATE: PerThreadState<
BumpAllocator<ArenaMemorySource<MemoryMapSource>>,
MultipleBinarySearchTreeAllocator<MemoryMapSource>,
> = PerThreadState::empty();
Expand Down Expand Up @@ -55,14 +55,14 @@ unsafe impl GlobalAlloc for GlobalThreadAndCoroutineSwitchableAllocatorInstance
self.GlobalAlloc_alloc(layout)
}
#[inline(always)]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
self.GlobalAlloc_alloc_zeroed(layout)
}
#[inline(always)]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
self.GlobalAlloc_dealloc(ptr, layout)
}
#[inline(always)]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
self.GlobalAlloc_alloc_zeroed(layout)
}
#[inline(always)]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
self.GlobalAlloc_realloc(ptr, layout, new_size)
}
Expand All @@ -74,10 +74,6 @@ unsafe impl Alloc for GlobalThreadAndCoroutineSwitchableAllocatorInstance {
self.Alloc_alloc(layout)
}
#[inline(always)]
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<MemoryAddress, AllocErr> {
self.Alloc_alloc_zeroed(layout)
}
#[inline(always)]
unsafe fn dealloc(&mut self, ptr: MemoryAddress, layout: Layout) {
self.Alloc_dealloc(ptr, layout)
}
Expand All @@ -91,6 +87,10 @@ unsafe impl Alloc for GlobalThreadAndCoroutineSwitchableAllocatorInstance {
self.Alloc_realloc(ptr, layout, new_size)
}
#[inline(always)]
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<MemoryAddress, AllocErr> {
self.Alloc_alloc_zeroed(layout)
}
#[inline(always)]
unsafe fn alloc_excess(&mut self, layout: Layout) -> Result<Excess, AllocErr> {
self.Alloc_alloc_excess(layout)
}
Expand Down Expand Up @@ -277,15 +277,15 @@ impl GlobalThreadAndCoroutineSwitchableAllocator
&self,
replacement: Option<Self::CoroutineLocalAllocator>,
) -> Option<Self::CoroutineLocalAllocator> {
unsafe { replace(&mut per_thread_state.coroutine_local_allocator, replacement) }
unsafe { replace(&mut PER_THREAD_STATE.coroutine_local_allocator, replacement) }
}
#[inline(always)]
fn initialize_thread_local_allocator(
&self,
thread_local_allocator: Self::ThreadLocalAllocator,
) {
if true {
if !unsafe { per_thread_state.thread_local_allocator.is_none() } {
if !unsafe { PER_THREAD_STATE.thread_local_allocator.is_none() } {
{
::std::rt::begin_panic(
"Already initialized thread local allocator",
Expand All @@ -294,12 +294,12 @@ impl GlobalThreadAndCoroutineSwitchableAllocator
}
};
};
unsafe { per_thread_state.thread_local_allocator = Some(thread_local_allocator) }
unsafe { PER_THREAD_STATE.thread_local_allocator = Some(thread_local_allocator) }
}
#[inline(always)]
fn drop_thread_local_allocator(&self) {
if true {
if !unsafe { per_thread_state.thread_local_allocator.is_some() } {
if !unsafe { PER_THREAD_STATE.thread_local_allocator.is_some() } {
{
::std::rt::begin_panic(
"Already deinitialized thread local allocator",
Expand All @@ -308,23 +308,23 @@ impl GlobalThreadAndCoroutineSwitchableAllocator
}
};
};
unsafe { per_thread_state.thread_local_allocator = None }
unsafe { PER_THREAD_STATE.thread_local_allocator = None }
}
#[inline(always)]
fn save_current_allocator_in_use(&self) -> CurrentAllocatorInUse {
unsafe { per_thread_state.current_allocator_in_use }
unsafe { PER_THREAD_STATE.current_allocator_in_use }
}
#[inline(always)]
fn restore_current_allocator_in_use(&self, restore_to: CurrentAllocatorInUse) {
unsafe { per_thread_state.current_allocator_in_use = restore_to }
unsafe { PER_THREAD_STATE.current_allocator_in_use = restore_to }
}
#[inline(always)]
fn coroutine_local_allocator(&self) -> Option<&Self::CoroutineLocalAllocator> {
unsafe { per_thread_state.coroutine_local_allocator.as_ref() }
unsafe { PER_THREAD_STATE.coroutine_local_allocator.as_ref() }
}
#[inline(always)]
fn thread_local_allocator(&self) -> Option<&Self::ThreadLocalAllocator> {
unsafe { per_thread_state.thread_local_allocator.as_ref() }
unsafe { PER_THREAD_STATE.thread_local_allocator.as_ref() }
}
#[inline(always)]
fn global_allocator(&self) -> &Self::GlobalAllocator {
Expand Down
10 changes: 10 additions & 0 deletions bastion-executor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
//!
//!
//!
//! NUMA-aware SMP based Fault-tolerant Executor
//!
// Executing asm in some places
#![feature(asm)]
// Allocator features
#![feature(allocator_api)]
#![feature(core_intrinsics)]
#![feature(libstd_sys_internals)]
#![feature(thread_local)]
// Force missing implementations
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]

pub mod allocator;
pub mod blocking_pool;
Expand Down
4 changes: 1 addition & 3 deletions bastion-executor/src/load_balancer.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use super::placement;
use lazy_static::*;

use std::{thread, time};
use std::thread;

use super::load_balancer;
use crossbeam_utils::sync::ShardedLock;
use rustc_hash::FxHashMap;

const SIXTY_MILLIS: time::Duration = time::Duration::from_millis(60);

pub struct LoadBalancer();

impl LoadBalancer {
Expand Down
1 change: 1 addition & 0 deletions bastion-executor/src/sleepers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::{Condvar, Mutex};
///
/// Similar to how thread parking works, if a notification comes up while no threads are sleeping,
/// the next thread that attempts to go to sleep will pick up the notification immediately.
#[derive(Debug)]
pub struct Sleepers {
/// How many threads are currently a sleep.
sleep: Mutex<usize>,
Expand Down

0 comments on commit c9bc705

Please sign in to comment.