diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-07-13 10:33:14 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-22 19:35:41 +0100 |
commit | 91913fba595e9f692cadf141ea0f0c29f789ed7f (patch) | |
tree | feb2450a2aa901cb2651d61ecd43eccfb7db45e8 /Userland/Libraries | |
parent | 500dc83f32e59feb5416301a5caa11e15f87fe0c (diff) | |
download | serenity-91913fba595e9f692cadf141ea0f0c29f789ed7f.zip |
LibThreading: Add is_started state information to Thread
Users can now determine whether a thread has been started or not. A
started thread might also have already terminated.
Implementation note: We *could* detect this with pthread APIs maybe, but
this is much simpler.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibThreading/Thread.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibThreading/Thread.h | 2 |
2 files changed, 3 insertions, 0 deletions
diff --git a/Userland/Libraries/LibThreading/Thread.cpp b/Userland/Libraries/LibThreading/Thread.cpp index 7659793c29..d62684de98 100644 --- a/Userland/Libraries/LibThreading/Thread.cpp +++ b/Userland/Libraries/LibThreading/Thread.cpp @@ -45,6 +45,7 @@ void Threading::Thread::start() VERIFY(rc == 0); } dbgln("Started thread \"{}\", tid = {}", m_thread_name, m_tid); + m_started = true; } void Threading::Thread::detach() diff --git a/Userland/Libraries/LibThreading/Thread.h b/Userland/Libraries/LibThreading/Thread.h index 612403846d..dec19c248a 100644 --- a/Userland/Libraries/LibThreading/Thread.h +++ b/Userland/Libraries/LibThreading/Thread.h @@ -32,6 +32,7 @@ public: String thread_name() const { return m_thread_name; } pthread_t tid() const { return m_tid; } + bool is_started() const { return m_started; } private: explicit Thread(Function<intptr_t()> action, StringView thread_name = {}); @@ -39,6 +40,7 @@ private: pthread_t m_tid { 0 }; String m_thread_name; bool m_detached { false }; + bool m_started { false }; }; template<typename T> |