Skip to content

Commit

Permalink
Fix idm remove
Browse files Browse the repository at this point in the history
idm remove calls shared_ptr::exchange with a null_ptr.
This calls the stored object's constructor with null args.
Let's just add an exchange overload for null_ptr
  • Loading branch information
Megamouse committed Dec 29, 2024
1 parent 439d665 commit 915aa57
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rpcs3/Emu/NP/np_contexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ matching_ctx::matching_ctx(vm::ptr<SceNpId> npId, vm::ptr<SceNpMatchingHandler>
this->handler = handler;
this->arg = arg;
}
void matching_ctx::queue_callback(u32 req_id, s32 event, s32 error_code)
void matching_ctx::queue_callback(u32 req_id, s32 event, s32 error_code) const
{
if (handler)
{
Expand All @@ -249,7 +249,7 @@ void matching_ctx::queue_callback(u32 req_id, s32 event, s32 error_code)
});
}
}
void matching_ctx::queue_gui_callback(s32 event, s32 error_code)
void matching_ctx::queue_gui_callback(s32 event, s32 error_code) const
{
if (gui_handler)
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/NP/np_contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ struct matching_ctx
{
matching_ctx(vm::ptr<SceNpId> npid, vm::ptr<SceNpMatchingHandler> handler, vm::ptr<void> arg);

void queue_callback(u32 req_id, s32 event, s32 error_code);
void queue_gui_callback(s32 event, s32 error_code);
void queue_callback(u32 req_id, s32 event, s32 error_code) const;
void queue_gui_callback(s32 event, s32 error_code) const;

static const u32 id_base = 0x9001;
static const u32 id_step = 1;
Expand Down
14 changes: 14 additions & 0 deletions rpcs3/util/shared_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ namespace stx
return value;
}

[[nodiscard]] shared_type exchange(struct null_ptr_t) noexcept;

// Ineffective
[[nodiscard]] bool compare_exchange(shared_type& cmp_and_old, shared_type exch)
{
Expand Down Expand Up @@ -1141,6 +1143,18 @@ namespace stx
}

} null_ptr;

template <typename T>
atomic_ptr<T>::shared_type atomic_ptr<T>::exchange(null_ptr_t) noexcept
{
atomic_ptr old;
old.m_val.raw() = m_val.exchange(0);
old.m_val.raw() += 1;

shared_type result;
result.m_ptr = std::launder(ptr_to(old.m_val));
return result;
}
}

template <typename T>
Expand Down

0 comments on commit 915aa57

Please sign in to comment.