mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
Userland: Rename LibThread => LibThreading
Also rename the "LibThread" namespace to "Threading"
This commit is contained in:
parent
5729b4e9a5
commit
b5d73c834f
25 changed files with 69 additions and 69 deletions
|
@ -67,7 +67,7 @@ I'm also on [Patreon](https://www.patreon.com/serenityos) and [GitHub Sponsors](
|
|||
* Mathematical functions (LibM)
|
||||
* ELF file handling (LibELF)
|
||||
* POSIX threading (LibPthread)
|
||||
* Higher-level threading (LibThread)
|
||||
* Higher-level threading (LibThreading)
|
||||
* Transport Layer Security (LibTLS)
|
||||
* HTTP and HTTPS (LibHTTP)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ int main(int argc, char** argv)
|
|||
Optional<String> save_path;
|
||||
bool need_to_write_wav = false;
|
||||
|
||||
auto audio_thread = LibThread::Thread::construct([&] {
|
||||
auto audio_thread = Threading::Thread::construct([&] {
|
||||
auto audio = Core::File::construct("/dev/audio");
|
||||
if (!audio->open(Core::OpenMode::WriteOnly)) {
|
||||
dbgln("Can't open audio device: {}", audio->error_string());
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibDebug/DebugSession.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
#include <LibVT/TerminalWidget.h>
|
||||
#include <fcntl.h>
|
||||
#include <spawn.h>
|
||||
|
@ -621,7 +621,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
|
|||
}
|
||||
|
||||
Debugger::the().set_executable_path(get_project_executable_path());
|
||||
m_debugger_thread = LibThread::Thread::construct(Debugger::start_static);
|
||||
m_debugger_thread = Threading::Thread::construct(Debugger::start_static);
|
||||
m_debugger_thread->start();
|
||||
m_stop_action->set_enabled(true);
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <LibGUI/Scrollbar.h>
|
||||
#include <LibGUI/Splitter.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
|
@ -144,7 +144,7 @@ private:
|
|||
RefPtr<FindInFilesWidget> m_find_in_files_widget;
|
||||
RefPtr<DebugInfoWidget> m_debug_info_widget;
|
||||
RefPtr<DisassemblyWidget> m_disassembly_widget;
|
||||
RefPtr<LibThread::Thread> m_debugger_thread;
|
||||
RefPtr<Threading::Thread> m_debugger_thread;
|
||||
RefPtr<EditorWrapper> m_current_editor_in_execution;
|
||||
|
||||
RefPtr<GUI::Action> m_new_file_action;
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include <LibGUI/Notification.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
#include <LibVT/TerminalWidget.h>
|
||||
#include <fcntl.h>
|
||||
#include <spawn.h>
|
||||
|
|
|
@ -37,7 +37,7 @@ add_subdirectory(LibSyntax)
|
|||
add_subdirectory(LibSystem)
|
||||
add_subdirectory(LibTest)
|
||||
add_subdirectory(LibTextCodec)
|
||||
add_subdirectory(LibThread)
|
||||
add_subdirectory(LibThreading)
|
||||
add_subdirectory(LibTLS)
|
||||
add_subdirectory(LibTTF)
|
||||
add_subdirectory(LibVT)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <AK/ScopedValueRollback.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibELF/AuxiliaryVector.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <mallocdefs.h>
|
||||
|
@ -27,10 +27,10 @@
|
|||
|
||||
#define PAGE_ROUND_UP(x) ((((size_t)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
|
||||
|
||||
static LibThread::Lock& malloc_lock()
|
||||
static Threading::Lock& malloc_lock()
|
||||
{
|
||||
static u32 lock_storage[sizeof(LibThread::Lock) / sizeof(u32)];
|
||||
return *reinterpret_cast<LibThread::Lock*>(&lock_storage);
|
||||
static u32 lock_storage[sizeof(Threading::Lock) / sizeof(u32)];
|
||||
return *reinterpret_cast<Threading::Lock*>(&lock_storage);
|
||||
}
|
||||
|
||||
constexpr size_t number_of_chunked_blocks_to_keep_around_per_size_class = 4;
|
||||
|
@ -158,7 +158,7 @@ enum class CallerWillInitializeMemory {
|
|||
|
||||
static void* malloc_impl(size_t size, CallerWillInitializeMemory caller_will_initialize_memory)
|
||||
{
|
||||
LibThread::Locker locker(malloc_lock());
|
||||
Threading::Locker locker(malloc_lock());
|
||||
|
||||
if (s_log_malloc)
|
||||
dbgln("LibC: malloc({})", size);
|
||||
|
@ -279,7 +279,7 @@ static void free_impl(void* ptr)
|
|||
|
||||
g_malloc_stats.number_of_free_calls++;
|
||||
|
||||
LibThread::Locker locker(malloc_lock());
|
||||
Threading::Locker locker(malloc_lock());
|
||||
|
||||
void* block_base = (void*)((FlatPtr)ptr & ChunkedBlock::ChunkedBlock::block_mask);
|
||||
size_t magic = *(size_t*)block_base;
|
||||
|
@ -381,7 +381,7 @@ size_t malloc_size(void* ptr)
|
|||
{
|
||||
if (!ptr)
|
||||
return 0;
|
||||
LibThread::Locker locker(malloc_lock());
|
||||
Threading::Locker locker(malloc_lock());
|
||||
void* page_base = (void*)((FlatPtr)ptr & ChunkedBlock::block_mask);
|
||||
auto* header = (const CommonHeader*)page_base;
|
||||
auto size = header->m_size;
|
||||
|
@ -406,7 +406,7 @@ void* realloc(void* ptr, size_t size)
|
|||
if (!size)
|
||||
return nullptr;
|
||||
|
||||
LibThread::Locker locker(malloc_lock());
|
||||
Threading::Locker locker(malloc_lock());
|
||||
auto existing_allocation_size = malloc_size(ptr);
|
||||
|
||||
if (size <= existing_allocation_size) {
|
||||
|
@ -423,7 +423,7 @@ void* realloc(void* ptr, size_t size)
|
|||
|
||||
void __malloc_init()
|
||||
{
|
||||
new (&malloc_lock()) LibThread::Lock();
|
||||
new (&malloc_lock()) Threading::Lock();
|
||||
|
||||
s_in_userspace_emulator = (int)syscall(SC_emuctl, 0) != -ENOSYS;
|
||||
if (s_in_userspace_emulator) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <LibCore/LocalSocket.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
@ -54,7 +54,7 @@ struct EventLoopTimer {
|
|||
};
|
||||
|
||||
struct EventLoop::Private {
|
||||
LibThread::Lock lock;
|
||||
Threading::Lock lock;
|
||||
};
|
||||
|
||||
static EventLoop* s_main_event_loop;
|
||||
|
@ -372,7 +372,7 @@ void EventLoop::pump(WaitMode mode)
|
|||
|
||||
decltype(m_queued_events) events;
|
||||
{
|
||||
LibThread::Locker locker(m_private->lock);
|
||||
Threading::Locker locker(m_private->lock);
|
||||
events = move(m_queued_events);
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ void EventLoop::pump(WaitMode mode)
|
|||
}
|
||||
|
||||
if (m_exit_requested) {
|
||||
LibThread::Locker locker(m_private->lock);
|
||||
Threading::Locker 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());
|
||||
|
@ -416,7 +416,7 @@ void EventLoop::pump(WaitMode mode)
|
|||
|
||||
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
||||
{
|
||||
LibThread::Locker lock(m_private->lock);
|
||||
Threading::Locker 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));
|
||||
}
|
||||
|
@ -600,7 +600,7 @@ retry:
|
|||
|
||||
bool queued_events_is_empty;
|
||||
{
|
||||
LibThread::Locker locker(m_private->lock);
|
||||
Threading::Locker locker(m_private->lock);
|
||||
queued_events_is_empty = m_queued_events.is_empty();
|
||||
}
|
||||
|
||||
|
|
|
@ -117,4 +117,4 @@ set(GENERATED_SOURCES
|
|||
)
|
||||
|
||||
serenity_lib(LibGUI gui)
|
||||
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibRegex LibSyntax)
|
||||
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThreading LibRegex LibSyntax)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <LibGUI/FileSystemModel.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibThread/BackgroundAction.h>
|
||||
#include <LibThreading/BackgroundAction.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
|
@ -571,7 +571,7 @@ bool FileSystemModel::fetch_thumbnail_for(const Node& node)
|
|||
|
||||
auto weak_this = make_weak_ptr();
|
||||
|
||||
LibThread::BackgroundAction<RefPtr<Gfx::Bitmap>>::create(
|
||||
Threading::BackgroundAction<RefPtr<Gfx::Bitmap>>::create(
|
||||
[path] {
|
||||
return render_thumbnail(path);
|
||||
},
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
set(SOURCES
|
||||
BackgroundAction.cpp
|
||||
Thread.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibThread thread)
|
||||
target_link_libraries(LibThread LibC LibCore LibPthread)
|
|
@ -5,19 +5,19 @@
|
|||
*/
|
||||
|
||||
#include <AK/Queue.h>
|
||||
#include <LibThread/BackgroundAction.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/BackgroundAction.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
static LibThread::Lockable<Queue<Function<void()>>>* s_all_actions;
|
||||
static LibThread::Thread* s_background_thread;
|
||||
static Threading::Lockable<Queue<Function<void()>>>* s_all_actions;
|
||||
static Threading::Thread* s_background_thread;
|
||||
|
||||
static intptr_t background_thread_func()
|
||||
{
|
||||
while (true) {
|
||||
Function<void()> work_item;
|
||||
{
|
||||
LibThread::Locker locker(s_all_actions->lock());
|
||||
Threading::Locker locker(s_all_actions->lock());
|
||||
|
||||
if (!s_all_actions->resource().is_empty())
|
||||
work_item = s_all_actions->resource().dequeue();
|
||||
|
@ -33,20 +33,20 @@ static intptr_t background_thread_func()
|
|||
|
||||
static void init()
|
||||
{
|
||||
s_all_actions = new LibThread::Lockable<Queue<Function<void()>>>();
|
||||
s_background_thread = &LibThread::Thread::construct(background_thread_func).leak_ref();
|
||||
s_all_actions = new Threading::Lockable<Queue<Function<void()>>>();
|
||||
s_background_thread = &Threading::Thread::construct(background_thread_func).leak_ref();
|
||||
s_background_thread->set_name("Background thread");
|
||||
s_background_thread->start();
|
||||
}
|
||||
|
||||
LibThread::Lockable<Queue<Function<void()>>>& LibThread::BackgroundActionBase::all_actions()
|
||||
Threading::Lockable<Queue<Function<void()>>>& Threading::BackgroundActionBase::all_actions()
|
||||
{
|
||||
if (s_all_actions == nullptr)
|
||||
init();
|
||||
return *s_all_actions;
|
||||
}
|
||||
|
||||
LibThread::Thread& LibThread::BackgroundActionBase::background_thread()
|
||||
Threading::Thread& Threading::BackgroundActionBase::background_thread()
|
||||
{
|
||||
if (s_background_thread == nullptr)
|
||||
init();
|
|
@ -13,10 +13,10 @@
|
|||
#include <LibCore/Event.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
namespace LibThread {
|
||||
namespace Threading {
|
||||
|
||||
template<typename Result>
|
||||
class BackgroundAction;
|
7
Userland/Libraries/LibThreading/CMakeLists.txt
Normal file
7
Userland/Libraries/LibThreading/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
set(SOURCES
|
||||
BackgroundAction.cpp
|
||||
Thread.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibThreading threading)
|
||||
target_link_libraries(LibThreading LibC LibCore LibPthread)
|
|
@ -16,7 +16,7 @@
|
|||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
namespace LibThread {
|
||||
namespace Threading {
|
||||
|
||||
class Lock {
|
||||
public:
|
|
@ -4,12 +4,12 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
LibThread::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
|
||||
Threading::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
|
||||
: Core::Object(nullptr)
|
||||
, m_action(move(action))
|
||||
, m_thread_name(thread_name.is_null() ? "" : thread_name)
|
||||
|
@ -18,7 +18,7 @@ LibThread::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
|
|||
register_property("tid", [&] { return JsonValue { m_tid }; });
|
||||
}
|
||||
|
||||
LibThread::Thread::~Thread()
|
||||
Threading::Thread::~Thread()
|
||||
{
|
||||
if (m_tid) {
|
||||
dbgln("Destroying thread \"{}\"({}) while it is still running!", m_thread_name, m_tid);
|
||||
|
@ -26,7 +26,7 @@ LibThread::Thread::~Thread()
|
|||
}
|
||||
}
|
||||
|
||||
void LibThread::Thread::start()
|
||||
void Threading::Thread::start()
|
||||
{
|
||||
int rc = pthread_create(
|
||||
&m_tid,
|
|
@ -13,7 +13,7 @@
|
|||
#include <LibCore/Object.h>
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LibThread {
|
||||
namespace Threading {
|
||||
|
||||
TYPEDEF_DISTINCT_ORDERED_ID(intptr_t, ThreadError);
|
||||
|
|
@ -10,4 +10,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_bin(AudioServer)
|
||||
target_link_libraries(AudioServer LibCore LibThread LibIPC)
|
||||
target_link_libraries(AudioServer LibCore LibThreading LibIPC)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace AudioServer {
|
|||
|
||||
Mixer::Mixer()
|
||||
: m_device(Core::File::construct("/dev/audio", this))
|
||||
, m_sound_thread(LibThread::Thread::construct(
|
||||
, m_sound_thread(Threading::Thread::construct(
|
||||
[this] {
|
||||
mix();
|
||||
return 0;
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include <AK/WeakPtr.h>
|
||||
#include <LibAudio/Buffer.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibThread/Lock.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
namespace AudioServer {
|
||||
|
||||
|
@ -112,7 +112,7 @@ private:
|
|||
|
||||
RefPtr<Core::File> m_device;
|
||||
|
||||
NonnullRefPtr<LibThread::Thread> m_sound_thread;
|
||||
NonnullRefPtr<Threading::Thread> m_sound_thread;
|
||||
|
||||
bool m_muted { false };
|
||||
int m_main_volume { 100 };
|
||||
|
|
|
@ -28,5 +28,5 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_bin(WindowServer)
|
||||
target_link_libraries(WindowServer LibCore LibGfx LibThread LibPthread LibIPC)
|
||||
target_link_libraries(WindowServer LibCore LibGfx LibThreading LibIPC)
|
||||
serenity_install_headers(Services/WindowServer)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/StylePainter.h>
|
||||
#include <LibThread/BackgroundAction.h>
|
||||
#include <LibThreading/BackgroundAction.h>
|
||||
|
||||
namespace WindowServer {
|
||||
|
||||
|
@ -609,7 +609,7 @@ bool Compositor::set_wallpaper_mode(const String& mode)
|
|||
|
||||
bool Compositor::set_wallpaper(const String& path, Function<void(bool)>&& callback)
|
||||
{
|
||||
LibThread::BackgroundAction<RefPtr<Gfx::Bitmap>>::create(
|
||||
Threading::BackgroundAction<RefPtr<Gfx::Bitmap>>::create(
|
||||
[path] {
|
||||
return Gfx::Bitmap::load_from_file(path);
|
||||
},
|
||||
|
|
|
@ -50,7 +50,7 @@ target_link_libraries(tar LibArchive LibCompress)
|
|||
target_link_libraries(telws LibProtocol LibLine)
|
||||
target_link_libraries(test-crypto LibCrypto LibTLS LibLine)
|
||||
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
|
||||
target_link_libraries(test-pthread LibThread)
|
||||
target_link_libraries(test-pthread LibThreading)
|
||||
target_link_libraries(tt LibPthread)
|
||||
target_link_libraries(unzip LibArchive LibCompress)
|
||||
target_link_libraries(zip LibArchive LibCompress LibCrypto)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -17,10 +17,10 @@ static void test_once()
|
|||
static Vector<int> v;
|
||||
v.clear();
|
||||
pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
NonnullRefPtrVector<LibThread::Thread, threads_count> threads;
|
||||
NonnullRefPtrVector<Threading::Thread, threads_count> threads;
|
||||
|
||||
for (size_t i = 0; i < threads_count; i++) {
|
||||
threads.append(LibThread::Thread::construct([&] {
|
||||
threads.append(Threading::Thread::construct([&] {
|
||||
return pthread_once(&once, [] {
|
||||
v.append(35);
|
||||
sleep(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue