Skip to content

Commit c846832

Browse files
committed
smol runtime
1 parent 6a72d47 commit c846832

File tree

5 files changed

+171
-155
lines changed

5 files changed

+171
-155
lines changed

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ readme = "README.md"
88
repository = "https://github.com/ovnanova/atomalloc"
99

1010
[dependencies]
11-
tokio = { version = "1.41.0", features = ["full"] }
1211
crossbeam = "0.8.4"
12+
smol = "2.0.2"
1313

1414
[profile.release]
1515
lto = true
1616
codegen-units = 1
1717
panic = "abort"
1818
opt-level = 3
1919
strip = true
20+
21+
[dev-dependencies]
22+
macro_rules_attribute = "0.2.0"
23+
smol-macros = "0.1.1"

src/block.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Block {
5959
for (i, &byte) in data[chunk_start..chunk_end].iter().enumerate() {
6060
self.data[offset + chunk_start + i].store(byte, Ordering::Release);
6161
}
62-
tokio::task::yield_now().await;
62+
smol::future::yield_now().await;
6363
}
6464

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

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

110110
self.state.fetch_or(ZEROED_FLAG, Ordering::Release);
@@ -142,7 +142,7 @@ impl BlockOps for Block {
142142
for i in offset..end {
143143
block.data[i].store(0, Ordering::Release);
144144
}
145-
tokio::task::yield_now().await;
145+
smol::future::yield_now().await;
146146
}
147147

148148
block.state.fetch_or(ZEROED_FLAG, Ordering::Release);

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl AtomAlloc {
4242
stats.clone(),
4343
));
4444

45-
tokio::task::yield_now().await;
45+
smol::future::yield_now().await;
4646

4747
Self {
4848
pool,

src/stats.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,42 @@ impl AtomAllocStats {
3636

3737
pub async fn record_cache_hit(&self) {
3838
self.cache_hits.fetch_add(1, Ordering::Release);
39-
tokio::task::yield_now().await;
39+
smol::future::yield_now().await;
4040
}
4141

4242
pub async fn record_cache_miss(&self) {
4343
self.cache_misses.fetch_add(1, Ordering::Release);
44-
tokio::task::yield_now().await;
44+
smol::future::yield_now().await;
4545
}
4646

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

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

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

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

7272
pub async fn cache_misses(&self) -> usize {
7373
let result = self.cache_misses.load(Ordering::Acquire);
74-
tokio::task::yield_now().await;
74+
smol::future::yield_now().await;
7575
result
7676
}
7777
}

0 commit comments

Comments
 (0)