Skip to content

Commit 6586514

Browse files
authored
Merge pull request #12 from vinaychandra/patch-1
Update rescue to accept layout
2 parents 026a647 + 9d2c4b7 commit 6586514

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,21 @@ unsafe impl<const ORDER: usize> GlobalAlloc for LockedHeap<ORDER> {
274274
/// Create a locked heap:
275275
/// ```
276276
/// use buddy_system_allocator::*;
277-
/// let heap = LockedHeapWithRescue::new(|heap: &mut Heap<32>| {});
277+
/// let heap = LockedHeapWithRescue::new(|heap: &mut Heap<32>, layout: &core::alloc::Layout| {});
278278
/// ```
279279
///
280280
/// Before oom, the allocator will try to call rescue function and try for one more time.
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<ORDER>, &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()

src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn test_heap_oom() {
7777
#[test]
7878
fn test_heap_oom_rescue() {
7979
static mut SPACE: [usize; 100] = [0; 100];
80-
let heap = LockedHeapWithRescue::new(|heap: &mut Heap<32>| unsafe {
80+
let heap = LockedHeapWithRescue::new(|heap: &mut Heap<32>, _layout: &Layout| unsafe {
8181
heap.add_to_heap(SPACE.as_ptr() as usize, SPACE.as_ptr().add(100) as usize);
8282
});
8383

0 commit comments

Comments
 (0)