diff --git a/src/system/libroot/posix/malloc/Jamfile b/src/system/libroot/posix/malloc/Jamfile index 3cb65cc7a0..9a14024dd2 100644 --- a/src/system/libroot/posix/malloc/Jamfile +++ b/src/system/libroot/posix/malloc/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src system libroot posix malloc ; -UsePrivateHeaders libroot ; +UsePrivateHeaders libroot shared ; local architectureObject ; for architectureObject in [ MultiArchSubDirSetup ] { diff --git a/src/system/libroot/posix/malloc/arch-specific.cpp b/src/system/libroot/posix/malloc/arch-specific.cpp index 0f16100831..81a39945a8 100644 --- a/src/system/libroot/posix/malloc/arch-specific.cpp +++ b/src/system/libroot/posix/malloc/arch-specific.cpp @@ -41,12 +41,6 @@ void *(*sbrk_hook)(long) = &BPrivate::hoardSbrk; using namespace BPrivate; -// How many iterations we spin waiting for a lock. -enum { SPIN_LIMIT = 50 }; - -// The values of a user-level lock. -enum { UNLOCKED = 0, LOCKED = 1 }; - struct free_chunk { free_chunk *next; size_t size; @@ -368,35 +362,21 @@ hoardUnsbrk(void *ptr, long size) void hoardLockInit(hoardLockType &lock, const char *name) { - lock = UNLOCKED; + mutex_init(&lock, name); } void hoardLock(hoardLockType &lock) { - // A yielding lock (with an initial spin). - while (true) { - int32 i = 0; - while (i < SPIN_LIMIT) { - if (atomic_test_and_set(&lock, LOCKED, UNLOCKED) == UNLOCKED) { - // We got the lock. - return; - } - i++; - } - - // The lock is still being held by someone else. - // Give up our quantum. - hoardYield(); - } + mutex_lock(&lock); } void hoardUnlock(hoardLockType &lock) { - atomic_set(&lock, UNLOCKED); + mutex_unlock(&lock); } diff --git a/src/system/libroot/posix/malloc/arch-specific.h b/src/system/libroot/posix/malloc/arch-specific.h index bffd92310f..88760c2e38 100644 --- a/src/system/libroot/posix/malloc/arch-specific.h +++ b/src/system/libroot/posix/malloc/arch-specific.h @@ -27,8 +27,12 @@ #include #include +#include -typedef int32 hoardLockType; + +// TODO: some kind of adaptive mutex (i.e. trying to spin for a while before +// may be a better choice +typedef mutex hoardLockType; namespace BPrivate { diff --git a/src/system/libroot/posix/malloc/wrapper.cpp b/src/system/libroot/posix/malloc/wrapper.cpp index 2af067fa5b..294901d13c 100644 --- a/src/system/libroot/posix/malloc/wrapper.cpp +++ b/src/system/libroot/posix/malloc/wrapper.cpp @@ -46,7 +46,7 @@ using namespace BPrivate; #if HEAP_LEAK_CHECK static block* sUsedList = NULL; -static hoardLockType sUsedLock = 0; +static hoardLockType sUsedLock = MUTEX_INITIALIZER(""); /*!