Skip to content

Commit 501ee73

Browse files
committed
task: implement and initialize static lock-free verification queue
1 parent a63f5a8 commit 501ee73

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/task/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use core::{future::Future, pin::Pin, task::{Context, Poll}};
22
use alloc::boxed::Box;
3+
use crossbeam_queue::ArrayQueue;
4+
use conquer_once::spin::OnceCell;
5+
use crate::vfs::CachedVfsBlock;
36

47
pub mod executor;
58
pub mod keyboard;
@@ -21,32 +24,32 @@ impl Task {
2124
}
2225
}
2326

24-
use crate::vfs::CachedVfsBlock;
25-
2627
#[derive(Clone, Copy)]
2728
pub struct CryptoVerificationJob {
2829
pub block_ptr: *mut CachedVfsBlock,
2930
pub expected_hash: [u8; 32],
3031
}
3132

32-
pub struct VerificationQueue {
33-
pub jobs: [Option<CryptoVerificationJob>; 32],
34-
pub head: usize,
35-
pub tail: usize,
33+
// Global thread-safe async queue for block validation
34+
pub static VERIFICATION_QUEUE: OnceCell<ArrayQueue<CryptoVerificationJob>> = OnceCell::new();
35+
36+
pub fn init_queue() {
37+
VERIFICATION_QUEUE.init_once(|| ArrayQueue::new(32));
3638
}
3739

3840
pub fn spawn_provenance_worker() {
39-
4041
loop {
4142
if let Some(queue) = VERIFICATION_QUEUE.get() {
4243
if let Some(job) = queue.pop() {
43-
// Execute the cryptographic hashing off the main thread path
4444
unsafe {
4545
crate::provenance::process_next_provenance_job(job);
4646
}
4747
}
4848
}
49-
// Prevent raw CPU hogging in simulation
5049
core::hint::spin_loop();
5150
}
51+
}
52+
53+
pub fn yield_current_thread() {
54+
core::hint::spin_loop();
5255
}

0 commit comments

Comments
 (0)