summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-08-25 23:51:27 +0300
committerAndreas Kling <awesomekling@gmail.com>2019-08-26 11:31:14 +0200
commit3439a479afbb13f28a436b472e150a71c5b3b6ce (patch)
tree7efa15248b8a2108e67590ab70d1bc582306efcb
parent0826cc5a356382b168e6e95077d53e27ccae48eb (diff)
downloadserenity-3439a479afbb13f28a436b472e150a71c5b3b6ce.zip
LibThread: Move CLock to LibThread::Lock
And adapt all the code that uses it.
-rw-r--r--Libraries/LibC/malloc.cpp10
-rw-r--r--Libraries/LibCore/CEventLoop.cpp2
-rw-r--r--Libraries/LibCore/CEventLoop.h4
-rw-r--r--Libraries/LibThread/BackgroundAction.cpp8
-rw-r--r--Libraries/LibThread/BackgroundAction.h4
-rw-r--r--Libraries/LibThread/Lock.h (renamed from Libraries/LibCore/CLock.h)44
-rw-r--r--Servers/AudioServer/ASMixer.h4
7 files changed, 42 insertions, 34 deletions
diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp
index 7495966366..d5364f5161 100644
--- a/Libraries/LibC/malloc.cpp
+++ b/Libraries/LibC/malloc.cpp
@@ -2,7 +2,7 @@
#include <AK/InlineLinkedList.h>
#include <AK/ScopedValueRollback.h>
#include <AK/Vector.h>
-#include <LibCore/CLock.h>
+#include <LibThread/Lock.h>
#include <assert.h>
#include <mallocdefs.h>
#include <serenity.h>
@@ -19,10 +19,10 @@
#define MAGIC_BIGALLOC_HEADER 0x42697267
#define PAGE_ROUND_UP(x) ((((size_t)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
-static CLock& malloc_lock()
+static LibThread::Lock& malloc_lock()
{
- static u32 lock_storage[sizeof(CLock) / sizeof(u32)];
- return *reinterpret_cast<CLock*>(&lock_storage);
+ static u32 lock_storage[sizeof(LibThread::Lock) / sizeof(u32)];
+ return *reinterpret_cast<LibThread::Lock*>(&lock_storage);
}
static const int number_of_chunked_blocks_to_keep_around_per_size_class = 32;
@@ -317,7 +317,7 @@ void* realloc(void* ptr, size_t size)
void __malloc_init()
{
- new (&malloc_lock()) CLock();
+ new (&malloc_lock()) LibThread::Lock();
if (getenv("LIBC_NOSCRUB_MALLOC"))
s_scrub_malloc = false;
if (getenv("LIBC_NOSCRUB_FREE"))
diff --git a/Libraries/LibCore/CEventLoop.cpp b/Libraries/LibCore/CEventLoop.cpp
index ac4b7c6ae0..1d34d7299d 100644
--- a/Libraries/LibCore/CEventLoop.cpp
+++ b/Libraries/LibCore/CEventLoop.cpp
@@ -5,10 +5,10 @@
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CLocalSocket.h>
-#include <LibCore/CLock.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>
#include <LibCore/CSyscallUtils.h>
+#include <LibThread/Lock.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
diff --git a/Libraries/LibCore/CEventLoop.h b/Libraries/LibCore/CEventLoop.h
index aa7777b768..bf8700d779 100644
--- a/Libraries/LibCore/CEventLoop.h
+++ b/Libraries/LibCore/CEventLoop.h
@@ -7,7 +7,7 @@
#include <AK/WeakPtr.h>
#include <LibCore/CEvent.h>
#include <LibCore/CLocalServer.h>
-#include <LibCore/CLock.h>
+#include <LibThread/Lock.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
@@ -69,7 +69,7 @@ private:
static int s_wake_pipe_fds[2];
- CLock m_lock;
+ LibThread::Lock m_lock;
struct EventLoopTimer {
int timer_id { 0 };
diff --git a/Libraries/LibThread/BackgroundAction.cpp b/Libraries/LibThread/BackgroundAction.cpp
index 0f1ef2046a..bffb784511 100644
--- a/Libraries/LibThread/BackgroundAction.cpp
+++ b/Libraries/LibThread/BackgroundAction.cpp
@@ -1,9 +1,9 @@
#include <LibThread/BackgroundAction.h>
#include <LibThread/Thread.h>
-#include <LibCore/CLock.h>
+#include <LibThread/Lock.h>
#include <AK/Queue.h>
-static CLockable<Queue<Function<void()>>>* s_all_actions;
+static LibThread::Lockable<Queue<Function<void()>>>* s_all_actions;
static LibThread::Thread* s_background_thread;
static int background_thread_func()
@@ -27,13 +27,13 @@ static int background_thread_func()
static void init()
{
- s_all_actions = new CLockable<Queue<Function<void()>>>();
+ s_all_actions = new LibThread::Lockable<Queue<Function<void()>>>();
s_background_thread = new LibThread::Thread(background_thread_func);
s_background_thread->set_name("Background thread");
s_background_thread->start();
}
-CLockable<Queue<Function<void()>>>& LibThread::BackgroundActionBase::all_actions()
+LibThread::Lockable<Queue<Function<void()>>>& LibThread::BackgroundActionBase::all_actions()
{
if (s_all_actions == nullptr)
init();
diff --git a/Libraries/LibThread/BackgroundAction.h b/Libraries/LibThread/BackgroundAction.h
index 965ec7b0bf..67f5d99f4b 100644
--- a/Libraries/LibThread/BackgroundAction.h
+++ b/Libraries/LibThread/BackgroundAction.h
@@ -6,8 +6,8 @@
#include <AK/Queue.h>
#include <AK/RefCounted.h>
#include <LibCore/CEventLoop.h>
-#include <LibCore/CLock.h>
#include <LibCore/CObject.h>
+#include <LibThread/Lock.h>
#include <LibThread/Thread.h>
namespace LibThread {
@@ -22,7 +22,7 @@ class BackgroundActionBase {
private:
BackgroundActionBase() {}
- static CLockable<Queue<Function<void()>>>& all_actions();
+ static Lockable<Queue<Function<void()>>>& all_actions();
static Thread& background_thread();
};
diff --git a/Libraries/LibCore/CLock.h b/Libraries/LibThread/Lock.h
index 2c31751f92..a3aea5e13b 100644
--- a/Libraries/LibCore/CLock.h
+++ b/Libraries/LibThread/Lock.h
@@ -20,10 +20,12 @@ static inline u32 CAS(volatile u32* mem, u32 newval, u32 oldval)
return ret;
}
-class CLock {
+namespace LibThread {
+
+class Lock {
public:
- CLock() {}
- ~CLock() {}
+ Lock() {}
+ ~Lock() {}
void lock();
void unlock();
@@ -34,22 +36,22 @@ private:
int m_holder { -1 };
};
-class CLocker {
+class Locker {
public:
- [[gnu::always_inline]] inline explicit CLocker(CLock& l)
+ [[gnu::always_inline]] inline explicit Locker(Lock& l)
: m_lock(l)
{
lock();
}
- [[gnu::always_inline]] inline ~CLocker() { unlock(); }
+ [[gnu::always_inline]] inline ~Locker() { unlock(); }
[[gnu::always_inline]] inline void unlock() { m_lock.unlock(); }
[[gnu::always_inline]] inline void lock() { m_lock.lock(); }
private:
- CLock& m_lock;
+ Lock& m_lock;
};
-[[gnu::always_inline]] inline void CLock::lock()
+[[gnu::always_inline]] inline void Lock::lock()
{
int tid = gettid();
for (;;) {
@@ -67,7 +69,7 @@ private:
}
}
-inline void CLock::unlock()
+inline void Lock::unlock()
{
for (;;) {
if (CAS(&m_lock, 1, 0) == 0) {
@@ -88,17 +90,17 @@ inline void CLock::unlock()
}
}
-#define LOCKER(lock) CLocker locker(lock)
+#define LOCKER(lock) LibThread::Locker locker(lock)
template<typename T>
-class CLockable {
+class Lockable {
public:
- CLockable() {}
- CLockable(T&& resource)
+ Lockable() {}
+ Lockable(T&& resource)
: m_resource(move(resource))
{
}
- CLock& lock() { return m_lock; }
+ Lock& lock() { return m_lock; }
T& resource() { return m_resource; }
T lock_and_copy()
@@ -109,17 +111,23 @@ public:
private:
T m_resource;
- CLock m_lock;
+ Lock m_lock;
};
+}
+
#else
-class CLock {
+namespace LibThread {
+
+class Lock {
public:
- CLock() { }
- ~CLock() { }
+ Lock() { }
+ ~Lock() { }
};
+}
+
#define LOCKER(x)
#endif
diff --git a/Servers/AudioServer/ASMixer.h b/Servers/AudioServer/ASMixer.h
index 401ee455c3..0f2e869c05 100644
--- a/Servers/AudioServer/ASMixer.h
+++ b/Servers/AudioServer/ASMixer.h
@@ -7,7 +7,7 @@
#include <AK/WeakPtr.h>
#include <LibAudio/ABuffer.h>
#include <LibCore/CFile.h>
-#include <LibCore/CLock.h>
+#include <LibThread/Lock.h>
#include <LibThread/Thread.h>
class ASClientConnection;
@@ -64,7 +64,7 @@ private:
Vector<NonnullRefPtr<ASBufferQueue>> m_pending_mixing;
CFile m_device;
- CLock m_lock;
+ LibThread::Lock m_lock;
LibThread::Thread m_sound_thread;