Skip to content

Commit

Permalink
smol runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mekaem committed Oct 26, 2024
1 parent 6a72d47 commit c846832
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 155 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ readme = "README.md"
repository = "https://github.com/ovnanova/atomalloc"

[dependencies]
tokio = { version = "1.41.0", features = ["full"] }
crossbeam = "0.8.4"
smol = "2.0.2"

[profile.release]
lto = true
codegen-units = 1
panic = "abort"
opt-level = 3
strip = true

[dev-dependencies]
macro_rules_attribute = "0.2.0"
smol-macros = "0.1.1"
8 changes: 4 additions & 4 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Block {
for (i, &byte) in data[chunk_start..chunk_end].iter().enumerate() {
self.data[offset + chunk_start + i].store(byte, Ordering::Release);
}
tokio::task::yield_now().await;
smol::future::yield_now().await;
}

self.state.fetch_and(!ZEROED_FLAG, Ordering::Release);
Expand All @@ -81,7 +81,7 @@ impl Block {
for i in chunk_start..chunk_end {
result.push(self.data[offset + i].load(Ordering::Acquire));
}
tokio::task::yield_now().await;
smol::future::yield_now().await;
}

Ok(result)
Expand All @@ -104,7 +104,7 @@ impl Block {
for i in offset..end {
self.data[i].store(0, Ordering::Release);
}
tokio::task::yield_now().await;
smol::future::yield_now().await;
}

self.state.fetch_or(ZEROED_FLAG, Ordering::Release);
Expand Down Expand Up @@ -142,7 +142,7 @@ impl BlockOps for Block {
for i in offset..end {
block.data[i].store(0, Ordering::Release);
}
tokio::task::yield_now().await;
smol::future::yield_now().await;
}

block.state.fetch_or(ZEROED_FLAG, Ordering::Release);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl AtomAlloc {
stats.clone(),
));

tokio::task::yield_now().await;
smol::future::yield_now().await;

Self {
pool,
Expand Down
14 changes: 7 additions & 7 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,42 @@ impl AtomAllocStats {

pub async fn record_cache_hit(&self) {
self.cache_hits.fetch_add(1, Ordering::Release);
tokio::task::yield_now().await;
smol::future::yield_now().await;
}

pub async fn record_cache_miss(&self) {
self.cache_misses.fetch_add(1, Ordering::Release);
tokio::task::yield_now().await;
smol::future::yield_now().await;
}

// Stats retrieval
pub async fn allocated_bytes(&self) -> usize {
let result = self.total_allocated.load(Ordering::Acquire);
tokio::task::yield_now().await;
smol::future::yield_now().await;
result
}

pub async fn freed_bytes(&self) -> usize {
let result = self.total_freed.load(Ordering::Acquire);
tokio::task::yield_now().await;
smol::future::yield_now().await;
result
}

pub async fn current_bytes(&self) -> usize {
let result = self.current_allocated.load(Ordering::Acquire);
tokio::task::yield_now().await;
smol::future::yield_now().await;
result
}

pub async fn cache_hits(&self) -> usize {
let result = self.cache_hits.load(Ordering::Acquire);
tokio::task::yield_now().await;
smol::future::yield_now().await;
result
}

pub async fn cache_misses(&self) -> usize {
let result = self.cache_misses.load(Ordering::Acquire);
tokio::task::yield_now().await;
smol::future::yield_now().await;
result
}
}
Loading

0 comments on commit c846832

Please sign in to comment.