Fix idm remove

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
This commit is contained in:
Megamouse 2024-12-28 22:24:33 +01:00
commit 915aa572c0
3 changed files with 18 additions and 4 deletions

View file

@ -238,7 +238,7 @@ matching_ctx::matching_ctx(vm::ptr<SceNpId> npId, vm::ptr<SceNpMatchingHandler>
this->handler = handler; this->handler = handler;
this->arg = arg; 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) if (handler)
{ {
@ -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) if (gui_handler)
{ {

View file

@ -289,8 +289,8 @@ struct matching_ctx
{ {
matching_ctx(vm::ptr<SceNpId> npid, vm::ptr<SceNpMatchingHandler> handler, vm::ptr<void> arg); 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_callback(u32 req_id, s32 event, s32 error_code) const;
void queue_gui_callback(s32 event, s32 error_code); void queue_gui_callback(s32 event, s32 error_code) const;
static const u32 id_base = 0x9001; static const u32 id_base = 0x9001;
static const u32 id_step = 1; static const u32 id_step = 1;

View file

@ -895,6 +895,8 @@ namespace stx
return value; return value;
} }
[[nodiscard]] shared_type exchange(struct null_ptr_t) noexcept;
// Ineffective // Ineffective
[[nodiscard]] bool compare_exchange(shared_type& cmp_and_old, shared_type exch) [[nodiscard]] bool compare_exchange(shared_type& cmp_and_old, shared_type exch)
{ {
@ -1141,6 +1143,18 @@ namespace stx
} }
} null_ptr; } 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> template <typename T>