diff --git a/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.cpp b/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.cpp index a1f09e0167..e864080765 100644 --- a/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.cpp +++ b/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "PhysicalMemoryAllocator.h" @@ -97,7 +98,7 @@ PhysicalMemoryAllocator::PhysicalMemoryAllocator(const char *name, PhysicalMemoryAllocator::~PhysicalMemoryAllocator() { - _Lock(); + mutex_lock(&fLock); for (int32 i = 0; i < fArrayCount; i++) free(fArray[i]); @@ -113,20 +114,6 @@ PhysicalMemoryAllocator::~PhysicalMemoryAllocator() } -bool -PhysicalMemoryAllocator::_Lock() -{ - return (mutex_lock(&fLock) == B_OK); -} - - -void -PhysicalMemoryAllocator::_Unlock() -{ - mutex_unlock(&fLock); -} - - status_t PhysicalMemoryAllocator::Allocate(size_t size, void **logicalAddress, phys_addr_t *physicalAddress) @@ -169,7 +156,8 @@ PhysicalMemoryAllocator::Allocate(size_t size, void **logicalAddress, } } - if (!_Lock()) + MutexLocker locker(&fLock); + if (!locker.IsLocked()) return B_ERROR; while (true) { @@ -203,7 +191,6 @@ PhysicalMemoryAllocator::Allocate(size_t size, void **logicalAddress, arrayIndex >>= 1; } - _Unlock(); size_t offset = fBlockSize[arrayToUse] * i; *logicalAddress = (void *)((uint8 *)fLogicalBase + offset); *physicalAddress = (phys_addr_t)(fPhysicalBase + offset); @@ -217,7 +204,7 @@ PhysicalMemoryAllocator::Allocate(size_t size, void **logicalAddress, fNoMemoryCondition.Add(&entry); fMemoryWaitersCount++; - _Unlock(); + locker.Unlock(); TRACE_ERROR(("PMA: found no free slot to store %ld bytes, waiting\n", size)); @@ -227,7 +214,7 @@ PhysicalMemoryAllocator::Allocate(size_t size, void **logicalAddress, break; } - if (!_Lock()) + if (!locker.Lock()) return B_ERROR; fMemoryWaitersCount--; @@ -283,7 +270,8 @@ PhysicalMemoryAllocator::Deallocate(size_t size, void *logicalAddress, return B_BAD_VALUE; } - if (!_Lock()) + MutexLocker _(&fLock); + if (!_.IsLocked()) return B_ERROR; // clear upwards to the smallest block @@ -308,7 +296,6 @@ PhysicalMemoryAllocator::Deallocate(size_t size, void *logicalAddress, if (fMemoryWaitersCount > 0) fNoMemoryCondition.NotifyAll(); - _Unlock(); return B_OK; } diff --git a/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.h b/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.h index 053dcddcef..9fc27f7330 100644 --- a/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.h +++ b/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.h @@ -39,9 +39,6 @@ public: void DumpFreeSlots(); private: - bool _Lock(); - void _Unlock(); - char *fName; size_t fOverhead;