diff --git a/rust/scx_rustland_core/src/bpf.rs b/rust/scx_rustland_core/src/bpf.rs
index cee370451..4918ac9fb 100644
--- a/rust/scx_rustland_core/src/bpf.rs
+++ b/rust/scx_rustland_core/src/bpf.rs
@@ -174,6 +174,10 @@ struct AlignedBuffer([u8; BUFSIZE]);
static mut BUF: AlignedBuffer = AlignedBuffer([0; BUFSIZE]);
+// Special negative error code for libbpf to stop after consuming just one item from a BPF
+// ring buffer.
+const LIBBPF_STOP: i32 = -255;
+
impl<'cb> BpfScheduler<'cb> {
pub fn init(
slice_us: u64,
@@ -224,7 +228,7 @@ impl<'cb> BpfScheduler<'cb> {
// Maybe we should fix this to stop processing items from the ring buffer also when a
// value > 0 is returned.
//
- -255
+ LIBBPF_STOP
}
// Initialize online CPUs counter.
@@ -374,15 +378,16 @@ impl<'cb> BpfScheduler<'cb> {
// Receive a task to be scheduled from the BPF dispatcher.
//
// NOTE: if task.cpu is negative the task is exiting and it does not require to be scheduled.
- pub fn dequeue_task(&mut self) -> Result