mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:48:13 +00:00
Kernel: Use try_make_weak_ptr() instead of make_weak_ptr()
This commit is contained in:
parent
98c20b65cc
commit
c8ab7bde3b
7 changed files with 19 additions and 18 deletions
|
@ -128,7 +128,7 @@ protected:
|
||||||
// If called from an IRQ handler we need to delay evaluation
|
// If called from an IRQ handler we need to delay evaluation
|
||||||
// and unblocking of waiting threads. Note that this File
|
// and unblocking of waiting threads. Note that this File
|
||||||
// instance may be deleted until the deferred call is executed!
|
// instance may be deleted until the deferred call is executed!
|
||||||
Processor::deferred_call_queue([self = make_weak_ptr()]() {
|
Processor::deferred_call_queue([self = try_make_weak_ptr().release_value_but_fixme_should_propagate_errors()]() {
|
||||||
if (auto file = self.strong_ref())
|
if (auto file = self.strong_ref())
|
||||||
file->do_evaluate_block_conditions();
|
file->do_evaluate_block_conditions();
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
||||||
WeakPtr(const U& object)
|
WeakPtr(const U& object)
|
||||||
: m_link(object.template make_weak_ptr<U>().take_link())
|
: m_link(object.template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
WeakPtr(const U* object)
|
WeakPtr(const U* object)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
||||||
|
@ -69,7 +69,7 @@ public:
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
m_link = obj->template make_weak_ptr<U>().take_link();
|
m_link = obj->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +78,14 @@ public:
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
m_link = obj->template make_weak_ptr<U>().take_link();
|
m_link = obj->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
||||||
WeakPtr& operator=(const U& object)
|
WeakPtr& operator=(const U& object)
|
||||||
{
|
{
|
||||||
m_link = object.template make_weak_ptr<U>().take_link();
|
m_link = object.template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public:
|
||||||
WeakPtr& operator=(const U* object)
|
WeakPtr& operator=(const U* object)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
else
|
else
|
||||||
m_link = nullptr;
|
m_link = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -104,7 +104,7 @@ public:
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
m_link = obj->template make_weak_ptr<U>().take_link();
|
m_link = obj->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
else
|
else
|
||||||
m_link = nullptr;
|
m_link = nullptr;
|
||||||
});
|
});
|
||||||
|
@ -116,7 +116,7 @@ public:
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
m_link = obj->template make_weak_ptr<U>().take_link();
|
m_link = obj->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
else
|
else
|
||||||
m_link = nullptr;
|
m_link = nullptr;
|
||||||
});
|
});
|
||||||
|
|
|
@ -266,7 +266,8 @@ ErrorOr<void> Process::attach_resources(NonnullOwnPtr<Memory::AddressSpace>&& pr
|
||||||
first_thread->detach();
|
first_thread->detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_procfs_traits = TRY(ProcessProcFSTraits::try_create({}, *this));
|
auto weak_ptr = TRY(this->try_make_weak_ptr());
|
||||||
|
m_procfs_traits = TRY(ProcessProcFSTraits::try_create({}, move(weak_ptr)));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -724,9 +724,9 @@ public:
|
||||||
|
|
||||||
class ProcessProcFSTraits : public ProcFSExposedComponent {
|
class ProcessProcFSTraits : public ProcFSExposedComponent {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullRefPtr<ProcessProcFSTraits>> try_create(Badge<Process>, Process& process)
|
static ErrorOr<NonnullRefPtr<ProcessProcFSTraits>> try_create(Badge<Process>, WeakPtr<Process> process)
|
||||||
{
|
{
|
||||||
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcessProcFSTraits(process));
|
return adopt_nonnull_ref_or_enomem(new (nothrow) ProcessProcFSTraits(move(process)));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual InodeIndex component_index() const override;
|
virtual InodeIndex component_index() const override;
|
||||||
|
@ -738,8 +738,8 @@ public:
|
||||||
virtual GroupID owner_group() const override;
|
virtual GroupID owner_group() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ProcessProcFSTraits(Process& process)
|
explicit ProcessProcFSTraits(WeakPtr<Process> process)
|
||||||
: m_process(process.make_weak_ptr())
|
: m_process(move(process))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -404,10 +404,10 @@ static ErrorOr<LoadResult> load_elf_object(NonnullOwnPtr<Memory::AddressSpace> n
|
||||||
load_base_address,
|
load_base_address,
|
||||||
elf_image.entry().offset(load_offset).get(),
|
elf_image.entry().offset(load_offset).get(),
|
||||||
executable_size,
|
executable_size,
|
||||||
AK::make_weak_ptr_if_nonnull(master_tls_region),
|
TRY(AK::try_make_weak_ptr_if_nonnull(master_tls_region)),
|
||||||
master_tls_size,
|
master_tls_size,
|
||||||
master_tls_alignment,
|
master_tls_alignment,
|
||||||
stack_region->make_weak_ptr()
|
TRY(stack_region->try_make_weak_ptr())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -523,7 +523,7 @@ ErrorOr<FlatPtr> Process::sys$allocate_tls(Userspace<const char*> initial_data,
|
||||||
auto range = TRY(address_space().try_allocate_range({}, size));
|
auto range = TRY(address_space().try_allocate_range({}, size));
|
||||||
auto* region = TRY(address_space().allocate_region(range, "Master TLS"sv, PROT_READ | PROT_WRITE));
|
auto* region = TRY(address_space().allocate_region(range, "Master TLS"sv, PROT_READ | PROT_WRITE));
|
||||||
|
|
||||||
m_master_tls_region = region->make_weak_ptr();
|
m_master_tls_region = TRY(region->try_make_weak_ptr());
|
||||||
m_master_tls_size = size;
|
m_master_tls_size = size;
|
||||||
m_master_tls_alignment = PAGE_SIZE;
|
m_master_tls_alignment = PAGE_SIZE;
|
||||||
|
|
||||||
|
|
|
@ -359,7 +359,7 @@ void Thread::unblock_from_blocker(Blocker& blocker)
|
||||||
unblock();
|
unblock();
|
||||||
};
|
};
|
||||||
if (Processor::current_in_irq() != 0) {
|
if (Processor::current_in_irq() != 0) {
|
||||||
Processor::deferred_call_queue([do_unblock = move(do_unblock), self = make_weak_ptr()]() {
|
Processor::deferred_call_queue([do_unblock = move(do_unblock), self = try_make_weak_ptr().release_value_but_fixme_should_propagate_errors()]() {
|
||||||
if (auto this_thread = self.strong_ref())
|
if (auto this_thread = self.strong_ref())
|
||||||
do_unblock();
|
do_unblock();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue