Skip to content

Commit d9ad1c8

Browse files
authored
Update rescue to accept layout
Rescue is called to add more heap. Passing in layout can help to know how much to expand
1 parent 026a647 commit d9ad1c8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ unsafe impl<const ORDER: usize> GlobalAlloc for LockedHeap<ORDER> {
281281
#[cfg(feature = "use_spin")]
282282
pub struct LockedHeapWithRescue<const ORDER: usize> {
283283
inner: Mutex<Heap<ORDER>>,
284-
rescue: fn(&mut Heap<ORDER>),
284+
rescue: fn(&mut Heap<ORDER>, &Layout),
285285
}
286286

287287
#[cfg(feature = "use_spin")]
288288
impl<const ORDER: usize> LockedHeapWithRescue<ORDER> {
289289
/// Creates an empty heap
290290
#[cfg(feature = "const_fn")]
291-
pub const fn new(rescue: fn(&mut Heap)) -> Self {
291+
pub const fn new(rescue: fn(&mut Heap, &Layout)) -> Self {
292292
LockedHeapWithRescue {
293293
inner: Mutex::new(Heap::<ORDER>::new()),
294294
rescue,
@@ -297,7 +297,7 @@ impl<const ORDER: usize> LockedHeapWithRescue<ORDER> {
297297

298298
/// Creates an empty heap
299299
#[cfg(not(feature = "const_fn"))]
300-
pub fn new(rescue: fn(&mut Heap<ORDER>)) -> Self {
300+
pub fn new(rescue: fn(&mut Heap<ORDER>, &Layout)) -> Self {
301301
LockedHeapWithRescue {
302302
inner: Mutex::new(Heap::<ORDER>::new()),
303303
rescue,
@@ -321,7 +321,7 @@ unsafe impl<const ORDER: usize> GlobalAlloc for LockedHeapWithRescue<ORDER> {
321321
match inner.alloc(layout) {
322322
Ok(allocation) => allocation.as_ptr(),
323323
Err(_) => {
324-
(self.rescue)(&mut inner);
324+
(self.rescue)(&mut inner, &layout);
325325
inner
326326
.alloc(layout)
327327
.ok()

0 commit comments

Comments
 (0)