mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
LibThreading: Remove Thread's inheritance from Core::EventReceiver
Inheritance from `EventReceiver` on the `Thread` class was only used in the `BackgroundAction` class, where the children vector was keeping the action alive until the work was completed. However, this can be accomplished by instead capturing a `NonnullRefPtr` of `this`. The work function can then avoid having to remove the `BackgroundAction` from its parent `Thread` when the work completes.
This commit is contained in:
parent
925afcd4b0
commit
71df0ee994
3 changed files with 28 additions and 29 deletions
|
@ -41,10 +41,19 @@ enum class ThreadState : u8 {
|
|||
Joined,
|
||||
};
|
||||
|
||||
class Thread final : public Core::EventReceiver {
|
||||
C_OBJECT(Thread);
|
||||
|
||||
class Thread final
|
||||
: public RefCounted<Thread>
|
||||
, public Weakable<Thread> {
|
||||
public:
|
||||
static NonnullRefPtr<Thread> construct(Function<intptr_t()> action, StringView thread_name = {})
|
||||
{
|
||||
return adopt_ref(*new Thread(move(action), thread_name));
|
||||
}
|
||||
static ErrorOr<NonnullRefPtr<Thread>> try_create(Function<intptr_t()> action, StringView thread_name = {})
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) Thread(move(action), thread_name));
|
||||
}
|
||||
|
||||
virtual ~Thread();
|
||||
|
||||
ErrorOr<void> set_priority(int priority);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue