@@ -174,6 +174,10 @@ struct AlignedBuffer([u8; BUFSIZE]);
174174
175175static mut BUF : AlignedBuffer = AlignedBuffer ( [ 0 ; BUFSIZE ] ) ;
176176
177+ // Special negative error code for libbpf to stop after consuming just one item from a BPF
178+ // ring buffer.
179+ const LIBBPF_STOP : i32 = -255 ;
180+
177181impl < ' cb > BpfScheduler < ' cb > {
178182 pub fn init (
179183 slice_us : u64 ,
@@ -224,7 +228,7 @@ impl<'cb> BpfScheduler<'cb> {
224228 // Maybe we should fix this to stop processing items from the ring buffer also when a
225229 // value > 0 is returned.
226230 //
227- - 255
231+ LIBBPF_STOP
228232 }
229233
230234 // Initialize online CPUs counter.
@@ -374,15 +378,16 @@ impl<'cb> BpfScheduler<'cb> {
374378 // Receive a task to be scheduled from the BPF dispatcher.
375379 //
376380 // NOTE: if task.cpu is negative the task is exiting and it does not require to be scheduled.
377- pub fn dequeue_task ( & mut self ) -> Result < Option < QueuedTask > , libbpf_rs :: Error > {
378- match self . queued . consume ( ) {
379- Ok ( ( ) ) => Ok ( None ) ,
380- Err ( error ) if error . kind ( ) == libbpf_rs :: ErrorKind :: Other => {
381+ pub fn dequeue_task ( & mut self ) -> Result < Option < QueuedTask > , i32 > {
382+ match self . queued . consume_raw ( ) {
383+ 0 => Ok ( None ) ,
384+ LIBBPF_STOP => {
381385 // A valid task is received, convert data to a proper task struct.
382386 let task = unsafe { EnqueuedMessage :: from_bytes ( & BUF . 0 ) . to_queued_task ( ) } ;
383387 Ok ( Some ( task) )
384388 }
385- Err ( error) => Err ( error) ,
389+ res if res < 0 => Err ( res) ,
390+ res => panic ! ( "Unexpected return value from libbpf-rs::consume_raw(): {}" , res) ,
386391 }
387392 }
388393
0 commit comments