Browse Source

Reduce duplication

Tamir Duberstein 11 tháng trước cách đây
mục cha
commit
58e154e1bc
1 tập tin đã thay đổi với 8 bổ sung7 xóa
  1. 8 7
      aya/src/maps/perf/perf_buffer.rs

+ 8 - 7
aya/src/maps/perf/perf_buffer.rs

@@ -219,9 +219,12 @@ impl PerfBuffer {
 
         let head = unsafe { (*header).data_head } as usize;
         let mut tail = unsafe { (*header).data_tail } as usize;
-        while head != tail {
+        let result = loop {
+            if head == tail {
+                break Ok(());
+            }
             if buf_n == buffers.len() {
-                break;
+                break Ok(());
             }
 
             let buf = &mut buffers[buf_n];
@@ -243,18 +246,16 @@ impl PerfBuffer {
                 Err(e) => {
                     // we got an error and we didn't process any events, propagate the error
                     // and give the caller a chance to increase buffers
-                    atomic::fence(Ordering::SeqCst);
-                    unsafe { (*header).data_tail = tail as u64 };
-                    return Err(e);
+                    break Err(e);
                 }
             }
             tail += event_size;
-        }
+        };
 
         atomic::fence(Ordering::SeqCst);
         unsafe { (*header).data_tail = tail as u64 };
 
-        Ok(events)
+        result.map(|()| events)
     }
 }