Allow checking out AppendBufs from Pool

This commit is contained in:
Carl Lerche
2016-07-23 09:54:18 -07:00
parent d650404bb8
commit 41b722dee8
2 changed files with 37 additions and 1 deletions
+6 -1
View File
@@ -1,5 +1,5 @@
use super::{Mem, MemRef};
use buf::{ByteBuf, MutByteBuf};
use buf::{AppendBuf, ByteBuf, MutByteBuf};
use stable_heap as heap;
use std::{mem, ptr, isize, usize};
use std::cell::{Cell, UnsafeCell};
@@ -92,6 +92,11 @@ impl Pool {
})
}
pub fn new_append_buf(&self) -> Option<AppendBuf> {
let len = self.inner.buf_len as u32;
self.checkout().map(|mem| unsafe { AppendBuf::from_mem_ref(mem, len, 0) })
}
fn checkout(&self) -> Option<MemRef> {
unsafe {
let mut ptr = self.inner.next.load(Ordering::Acquire);