1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:37:35 +00:00

LibThreading: Rename Lock => Mutex

This commit is contained in:
Andreas Kling 2021-07-09 11:14:57 +02:00
parent ce5d2b4f16
commit b8a204c5b9
8 changed files with 37 additions and 37 deletions

View file

@ -8,7 +8,7 @@
#include <AK/ScopedValueRollback.h>
#include <AK/Vector.h>
#include <LibELF/AuxiliaryVector.h>
#include <LibThreading/Lock.h>
#include <LibThreading/Mutex.h>
#include <assert.h>
#include <errno.h>
#include <mallocdefs.h>
@ -24,10 +24,10 @@
#define RECYCLE_BIG_ALLOCATIONS
static Threading::Lock& malloc_lock()
static Threading::Mutex& malloc_lock()
{
alignas(Threading::Lock) static u8 lock_storage[sizeof(Threading::Lock)];
return *reinterpret_cast<Threading::Lock*>(lock_storage);
alignas(Threading::Mutex) static u8 lock_storage[sizeof(Threading::Mutex)];
return *reinterpret_cast<Threading::Mutex*>(lock_storage);
}
constexpr size_t number_of_hot_chunked_blocks_to_keep_around = 16;
@ -167,7 +167,7 @@ enum class CallerWillInitializeMemory {
static void* malloc_impl(size_t size, CallerWillInitializeMemory caller_will_initialize_memory)
{
Threading::Locker locker(malloc_lock());
Threading::MutexLocker locker(malloc_lock());
if (s_log_malloc)
dbgln("LibC: malloc({})", size);
@ -304,7 +304,7 @@ static void free_impl(void* ptr)
g_malloc_stats.number_of_free_calls++;
Threading::Locker locker(malloc_lock());
Threading::MutexLocker locker(malloc_lock());
void* block_base = (void*)((FlatPtr)ptr & ChunkedBlock::ChunkedBlock::block_mask);
size_t magic = *(size_t*)block_base;
@ -413,7 +413,7 @@ size_t malloc_size(void* ptr)
{
if (!ptr)
return 0;
Threading::Locker locker(malloc_lock());
Threading::MutexLocker locker(malloc_lock());
void* page_base = (void*)((FlatPtr)ptr & ChunkedBlock::block_mask);
auto* header = (const CommonHeader*)page_base;
auto size = header->m_size;
@ -440,7 +440,7 @@ void* realloc(void* ptr, size_t size)
return nullptr;
}
Threading::Locker locker(malloc_lock());
Threading::MutexLocker locker(malloc_lock());
auto existing_allocation_size = malloc_size(ptr);
if (size <= existing_allocation_size) {
@ -457,7 +457,7 @@ void* realloc(void* ptr, size_t size)
void __malloc_init()
{
new (&malloc_lock()) Threading::Lock();
new (&malloc_lock()) Threading::Mutex();
s_in_userspace_emulator = (int)syscall(SC_emuctl, 0) != -ENOSYS;
if (s_in_userspace_emulator) {

View file

@ -21,7 +21,7 @@
#include <LibCore/LocalSocket.h>
#include <LibCore/Notifier.h>
#include <LibCore/Object.h>
#include <LibThreading/Lock.h>
#include <LibThreading/Mutex.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@ -54,7 +54,7 @@ struct EventLoopTimer {
};
struct EventLoop::Private {
Threading::Lock lock;
Threading::Mutex lock;
};
static EventLoop* s_main_event_loop;
@ -370,7 +370,7 @@ void EventLoop::pump(WaitMode mode)
decltype(m_queued_events) events;
{
Threading::Locker locker(m_private->lock);
Threading::MutexLocker locker(m_private->lock);
events = move(m_queued_events);
}
@ -399,7 +399,7 @@ void EventLoop::pump(WaitMode mode)
}
if (m_exit_requested) {
Threading::Locker locker(m_private->lock);
Threading::MutexLocker locker(m_private->lock);
dbgln_if(EVENTLOOP_DEBUG, "Core::EventLoop: Exit requested. Rejigging {} events.", events.size() - i);
decltype(m_queued_events) new_event_queue;
new_event_queue.ensure_capacity(m_queued_events.size() + events.size());
@ -414,7 +414,7 @@ void EventLoop::pump(WaitMode mode)
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
{
Threading::Locker lock(m_private->lock);
Threading::MutexLocker lock(m_private->lock);
dbgln_if(EVENTLOOP_DEBUG, "Core::EventLoop::post_event: ({}) << receivier={}, event={}", m_queued_events.size(), receiver, event);
m_queued_events.empend(receiver, move(event));
}
@ -598,7 +598,7 @@ retry:
bool queued_events_is_empty;
{
Threading::Locker locker(m_private->lock);
Threading::MutexLocker locker(m_private->lock);
queued_events_is_empty = m_queued_events.is_empty();
}

View file

@ -7,7 +7,7 @@
#include <AK/Queue.h>
#include <LibThreading/BackgroundAction.h>
#include <LibThreading/Lock.h>
#include <LibThreading/Mutex.h>
#include <LibThreading/Thread.h>
#include <unistd.h>

View file

@ -12,9 +12,9 @@
namespace Threading {
class Lock {
class Mutex {
public:
Lock()
Mutex()
{
#ifndef __serenity__
pthread_mutexattr_t attr;
@ -23,7 +23,7 @@ public:
pthread_mutex_init(&m_mutex, &attr);
#endif
}
~Lock() { }
~Mutex() { }
void lock();
void unlock();
@ -36,27 +36,27 @@ private:
#endif
};
class Locker {
class MutexLocker {
public:
ALWAYS_INLINE explicit Locker(Lock& l)
: m_lock(l)
ALWAYS_INLINE explicit MutexLocker(Mutex& mutex)
: m_mutex(mutex)
{
lock();
}
ALWAYS_INLINE ~Locker() { unlock(); }
ALWAYS_INLINE void unlock() { m_lock.unlock(); }
ALWAYS_INLINE void lock() { m_lock.lock(); }
ALWAYS_INLINE ~MutexLocker() { unlock(); }
ALWAYS_INLINE void unlock() { m_mutex.unlock(); }
ALWAYS_INLINE void lock() { m_mutex.lock(); }
private:
Lock& m_lock;
Mutex& m_mutex;
};
ALWAYS_INLINE void Lock::lock()
ALWAYS_INLINE void Mutex::lock()
{
pthread_mutex_lock(&m_mutex);
}
inline void Lock::unlock()
ALWAYS_INLINE void Mutex::unlock()
{
pthread_mutex_unlock(&m_mutex);
}