1
0
mirror of https://github.com/bspeice/qadapt synced 2025-07-03 06:45:02 -04:00

Takes us 576 allocations to get up and running

I need a better way to handle initialization costs...
This commit is contained in:
2018-09-22 16:13:36 -04:00
parent a489f71ae2
commit aafec768ca
3 changed files with 25 additions and 3 deletions

View File

@ -1,5 +1,7 @@
extern crate backtrace;
extern crate libc;
use backtrace::Backtrace;
use libc::c_void;
use libc::free;
use libc::malloc;
@ -11,12 +13,13 @@ use std::sync::atomic::Ordering;
mod const_init;
use const_init::ConstInit;
static mut INIT_ALLOCATIONS: u32 = 576;
pub struct QADAPT {
pub has_allocated: AtomicBool
}
impl ConstInit for QADAPT {
const INIT: QADAPT = QADAPT {
has_allocated: AtomicBool::new(false)
};
@ -25,7 +28,12 @@ impl ConstInit for QADAPT {
unsafe impl GlobalAlloc for QADAPT {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let block = malloc(layout.size()) as *mut u8;
self.has_allocated.store(true, Ordering::SeqCst);
if INIT_ALLOCATIONS > 0 {
INIT_ALLOCATIONS -= 1;
} else {
self.has_allocated.store(true, Ordering::SeqCst);
}
block
}