diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-05 21:48:04 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 01:55:27 +0200 |
commit | 98dc08fe560a1ef91ec2ae8d1a56e2d5e0b6f77f (patch) | |
tree | 28d4c836c6463fdb95a11dad871ea2d0a385d1d8 /Kernel/ProcessGroup.cpp | |
parent | 540d62d3b252657267468df4030e4bc5e86d76d7 (diff) | |
download | serenity-98dc08fe560a1ef91ec2ae8d1a56e2d5e0b6f77f.zip |
Kernel: Use KResultOr better in ProcessGroup construction
This allows us to use TRY() more.
Diffstat (limited to 'Kernel/ProcessGroup.cpp')
-rw-r--r-- | Kernel/ProcessGroup.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/Kernel/ProcessGroup.cpp b/Kernel/ProcessGroup.cpp index 609906dc12..086cf3491a 100644 --- a/Kernel/ProcessGroup.cpp +++ b/Kernel/ProcessGroup.cpp @@ -24,27 +24,24 @@ ProcessGroup::~ProcessGroup() }); } -RefPtr<ProcessGroup> ProcessGroup::try_create(ProcessGroupID pgid) +KResultOr<NonnullRefPtr<ProcessGroup>> ProcessGroup::try_create(ProcessGroupID pgid) { - auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid)); - if (!process_group) - return {}; + auto process_group = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessGroup(pgid))); process_groups().with([&](auto& groups) { groups.prepend(*process_group); }); return process_group; } -RefPtr<ProcessGroup> ProcessGroup::try_find_or_create(ProcessGroupID pgid) +KResultOr<NonnullRefPtr<ProcessGroup>> ProcessGroup::try_find_or_create(ProcessGroupID pgid) { - return process_groups().with([&](auto& groups) -> RefPtr<ProcessGroup> { + return process_groups().with([&](auto& groups) -> KResultOr<NonnullRefPtr<ProcessGroup>> { for (auto& group : groups) { if (group.pgid() == pgid) - return &group; + return group; } - auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid)); - if (process_group) - groups.prepend(*process_group); + auto process_group = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessGroup(pgid))); + groups.prepend(*process_group); return process_group; }); } |