numinnex commented on code in PR #2944:
URL: https://github.com/apache/iggy/pull/2944#discussion_r2944748214
##########
core/buf/src/lib.rs:
##########
@@ -0,0 +1,381 @@
+use std::mem::ManuallyDrop;
+use std::ptr::NonNull;
+use std::slice;
+use std::sync::atomic::{AtomicUsize, Ordering, fence};
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Owned {
+ inner: Vec<u8>,
+}
+
+#[derive(Clone, Copy)]
+struct Half {
+ ptr: NonNull<u8>,
+ len: usize,
+ ctrlb: NonNull<ControlBlock>,
+}
+
+struct ControlBlock {
+ ref_count: AtomicUsize,
+ base: NonNull<u8>,
+ len: usize,
+ cap: usize,
+}
+
+fn create_control_block(base: NonNull<u8>, len: usize, cap: usize) ->
NonNull<ControlBlock> {
+ let ctrlb = Box::new(ControlBlock {
+ ref_count: AtomicUsize::new(1),
+ base,
+ len,
+ cap,
+ });
+ // SAFETY: `ctrlb` is a valid control block for the lifetime of the
returned halves.
+ unsafe { NonNull::new_unchecked(Box::into_raw(ctrlb)) }
+}
+
+pub struct TwoHalves {
Review Comment:
I wanted to create general purpose mechanism for an split buffer. Yes we
will use it for header + body of `Message`, but we might want to use it for
something else aswell.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]