mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +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
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DistinctNumeric.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Result.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LibThread {
|
||||
|
||||
TYPEDEF_DISTINCT_ORDERED_ID(intptr_t, ThreadError);
|
||||
|
||||
class Thread final : public Core::Object {
|
||||
C_OBJECT(Thread);
|
||||
|
||||
public:
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
|
||||
template<typename T = void>
|
||||
Result<T, ThreadError> join();
|
||||
|
||||
String thread_name() const { return m_thread_name; }
|
||||
pthread_t tid() const { return m_tid; }
|
||||
|
||||
private:
|
||||
explicit Thread(Function<intptr_t()> action, StringView thread_name = nullptr);
|
||||
Function<intptr_t()> m_action;
|
||||
pthread_t m_tid { 0 };
|
||||
String m_thread_name;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Result<T, ThreadError> Thread::join()
|
||||
{
|
||||
void* thread_return = nullptr;
|
||||
int rc = pthread_join(m_tid, &thread_return);
|
||||
if (rc != 0) {
|
||||
return ThreadError { rc };
|
||||
}
|
||||
|
||||
m_tid = 0;
|
||||
if constexpr (IsVoid<T>)
|
||||
return {};
|
||||
else
|
||||
return { static_cast<T>(thread_return) };
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue