1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57: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

@ -16,7 +16,7 @@
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/TextBox.h> #include <LibGUI/TextBox.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
#include <LibThreading/Lock.h> #include <LibThreading/Mutex.h>
#include <unistd.h> #include <unistd.h>
namespace Assistant { namespace Assistant {
@ -26,7 +26,7 @@ struct AppState {
NonnullRefPtrVector<Result> results; NonnullRefPtrVector<Result> results;
size_t visible_result_count { 0 }; size_t visible_result_count { 0 };
Threading::Lock lock; Threading::Mutex lock;
String last_query; String last_query;
}; };
@ -143,7 +143,7 @@ private:
void did_receive_results(String const& query, NonnullRefPtrVector<Result> const& results) void did_receive_results(String const& query, NonnullRefPtrVector<Result> const& results)
{ {
{ {
Threading::Locker db_locker(m_lock); Threading::MutexLocker db_locker(m_mutex);
auto it = m_result_cache.find(query); auto it = m_result_cache.find(query);
if (it == m_result_cache.end()) { if (it == m_result_cache.end()) {
m_result_cache.set(query, {}); m_result_cache.set(query, {});
@ -160,7 +160,7 @@ private:
} }
} }
Threading::Locker state_locker(m_state.lock); Threading::MutexLocker state_locker(m_state.lock);
auto new_results = m_result_cache.find(m_state.last_query); auto new_results = m_result_cache.find(m_state.last_query);
if (new_results == m_result_cache.end()) if (new_results == m_result_cache.end())
return; return;
@ -181,7 +181,7 @@ private:
NonnullOwnPtrVector<Provider> m_providers; NonnullOwnPtrVector<Provider> m_providers;
Threading::Lock m_lock; Threading::Mutex m_mutex;
HashMap<String, NonnullRefPtrVector<Result>> m_result_cache; HashMap<String, NonnullRefPtrVector<Result>> m_result_cache;
}; };
@ -223,7 +223,7 @@ int main(int argc, char** argv)
text_box.on_change = [&]() { text_box.on_change = [&]() {
{ {
Threading::Locker locker(app_state.lock); Threading::MutexLocker locker(app_state.lock);
if (app_state.last_query == text_box.text()) if (app_state.last_query == text_box.text())
return; return;

View file

@ -11,7 +11,7 @@
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibDebug/DebugSession.h> #include <LibDebug/DebugSession.h>
#include <LibThreading/Lock.h> #include <LibThreading/Mutex.h>
#include <LibThreading/Thread.h> #include <LibThreading/Thread.h>
namespace HackStudio { namespace HackStudio {

View file

@ -62,7 +62,7 @@
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibGfx/FontDatabase.h> #include <LibGfx/FontDatabase.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
#include <LibThreading/Lock.h> #include <LibThreading/Mutex.h>
#include <LibThreading/Thread.h> #include <LibThreading/Thread.h>
#include <LibVT/TerminalWidget.h> #include <LibVT/TerminalWidget.h>
#include <fcntl.h> #include <fcntl.h>

View file

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

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@
#include <AK/WeakPtr.h> #include <AK/WeakPtr.h>
#include <LibAudio/Buffer.h> #include <LibAudio/Buffer.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibThreading/Lock.h> #include <LibThreading/Mutex.h>
#include <LibThreading/Thread.h> #include <LibThreading/Thread.h>
namespace AudioServer { namespace AudioServer {