Remove lv2_event_queue::check(weak_ptr)

This commit is contained in:
Eladash 2021-05-14 20:10:47 +03:00 committed by Ivan
parent c681395fb2
commit 8bd58b1ad4
8 changed files with 33 additions and 39 deletions

View File

@ -1575,7 +1575,7 @@ error_code AudioSetNotifyEventQueue(u64 key, u32 iFlags)
return CELL_AUDIO_ERROR_TRANS_EVENT;
}
if (!lv2_event_queue::check(i->port))
if (!lv2_obj::check(i->port))
{
// Cleanup, avoid cases where there are multiple ports with the same key
i = g_audio.keys.erase(i);
@ -1625,7 +1625,7 @@ error_code AudioRemoveNotifyEventQueue(u64 key, u32 iFlags)
for (auto i = g_audio.keys.cbegin(); i != g_audio.keys.cend(); i++)
{
if (lv2_event_queue::check(i->port) && i->port->key == key)
if (lv2_obj::check(i->port) && i->port->key == key)
{
if (i->flags != iFlags)
{

View File

@ -1160,9 +1160,9 @@ void spu_int_ctrl_t::set(u64 ints)
{
std::shared_lock rlock(id_manager::g_mutex);
if (tag && tag->exists)
if (lv2_obj::check(tag))
{
if (auto handler = tag->handler; handler && handler->exists)
if (auto handler = tag->handler; lv2_obj::check(handler))
{
rlock.unlock();
handler->exec();
@ -4379,7 +4379,7 @@ bool spu_thread::stop_and_signal(u32 code)
{
if (spuq == v.first)
{
if (lv2_event_queue::check(v.second))
if (lv2_obj::check(v.second))
{
queue = v.second.get();
break;
@ -4499,7 +4499,7 @@ bool spu_thread::stop_and_signal(u32 code)
{
if (spuq == v.first)
{
if (lv2_event_queue::check(v.second))
if (lv2_obj::check(v.second))
{
queue = v.second.get();
break;

View File

@ -32,18 +32,6 @@ std::shared_ptr<lv2_event_queue> lv2_event_queue::find(u64 ipc_key)
return g_fxo->get<ipc_manager<lv2_event_queue, u64>>().get(ipc_key);
}
bool lv2_event_queue::check(const std::weak_ptr<lv2_event_queue>& wkptr)
{
const auto queue = wkptr.lock();
return queue && queue->exists;
}
bool lv2_event_queue::check(const std::shared_ptr<lv2_event_queue>& sptr)
{
return sptr && sptr->exists;
}
CellError lv2_event_queue::send(lv2_event event)
{
std::lock_guard lock(mutex);
@ -372,7 +360,7 @@ error_code sys_event_port_destroy(ppu_thread& ppu, u32 eport_id)
const auto port = idm::withdraw<lv2_obj, lv2_event_port>(eport_id, [](lv2_event_port& port) -> CellError
{
if (lv2_event_queue::check(port.queue))
if (lv2_obj::check(port.queue))
{
return CELL_EISCONN;
}
@ -413,7 +401,7 @@ error_code sys_event_port_connect_local(cpu_thread& cpu, u32 eport_id, u32 equeu
return CELL_EINVAL;
}
if (lv2_event_queue::check(port->queue))
if (lv2_obj::check(port->queue))
{
return CELL_EISCONN;
}
@ -450,7 +438,7 @@ error_code sys_event_port_connect_ipc(ppu_thread& ppu, u32 eport_id, u64 ipc_key
return CELL_EINVAL;
}
if (lv2_event_queue::check(port->queue))
if (lv2_obj::check(port->queue))
{
return CELL_EISCONN;
}
@ -475,7 +463,7 @@ error_code sys_event_port_disconnect(ppu_thread& ppu, u32 eport_id)
return CELL_ESRCH;
}
if (!lv2_event_queue::check(port->queue))
if (!lv2_obj::check(port->queue))
{
return CELL_ENOTCONN;
}
@ -498,7 +486,7 @@ error_code sys_event_port_send(u32 eport_id, u64 data1, u64 data2, u64 data3)
const auto port = idm::get<lv2_obj, lv2_event_port>(eport_id, [&](lv2_event_port& port) -> CellError
{
if (lv2_event_queue::check(port.queue))
if (lv2_obj::check(port.queue))
{
const u64 source = port.name ? port.name : (s64{process_getpid()} << 32) | u64{eport_id};

View File

@ -63,7 +63,7 @@ error_code sys_interrupt_tag_destroy(ppu_thread& ppu, u32 intrtag)
const auto tag = idm::withdraw<lv2_obj, lv2_int_tag>(intrtag, [](lv2_int_tag& tag) -> CellError
{
if (tag.handler && tag.handler->exists)
if (lv2_obj::check(tag.handler))
{
return CELL_EBUSY;
}
@ -123,7 +123,7 @@ error_code _sys_interrupt_thread_establish(ppu_thread& ppu, vm::ptr<u32> ih, u32
}
// It's unclear if multiple handlers can be established on single interrupt tag
if (tag->handler && tag->handler->exists)
if (lv2_obj::check(tag->handler))
{
error = CELL_ESTAT;
return result;

View File

@ -1432,7 +1432,7 @@ error_code sys_spu_thread_group_connect_event(ppu_thread& ppu, u32 id, u32 eq, u
std::lock_guard lock(group->mutex);
if (lv2_event_queue::check(*ep))
if (lv2_obj::check(*ep))
{
return CELL_EBUSY;
}
@ -1474,7 +1474,7 @@ error_code sys_spu_thread_group_disconnect_event(ppu_thread& ppu, u32 id, u32 et
std::lock_guard lock(group->mutex);
if (!lv2_event_queue::check(*ep))
if (!lv2_obj::check(*ep))
{
return CELL_EINVAL;
}
@ -1507,7 +1507,7 @@ error_code sys_spu_thread_connect_event(ppu_thread& ppu, u32 id, u32 eq, u32 et,
auto& port = thread->spup[spup];
if (lv2_event_queue::check(port))
if (lv2_obj::check(port))
{
return CELL_EISCONN;
}
@ -1540,7 +1540,7 @@ error_code sys_spu_thread_disconnect_event(ppu_thread& ppu, u32 id, u32 et, u8 s
auto& port = thread->spup[spup];
if (!lv2_event_queue::check(port))
if (!lv2_obj::check(port))
{
return CELL_ENOTCONN;
}
@ -1683,7 +1683,7 @@ error_code sys_spu_thread_group_connect_event_all_threads(ppu_thread& ppu, u32 i
{
if (t)
{
if (lv2_event_queue::check(t->spup[port]))
if (lv2_obj::check(t->spup[port]))
{
found = false;
break;
@ -1938,9 +1938,9 @@ error_code raw_spu_destroy(ppu_thread& ppu, u32 id)
// Clear interrupt handlers
for (auto& intr : thread->int_ctrl)
{
if (auto& tag = intr.tag; tag && tag->exists)
if (auto& tag = intr.tag; lv2_obj::check(tag))
{
if (auto& handler = tag->handler; handler && handler->exists)
if (auto& handler = tag->handler; lv2_obj::check(handler))
{
// SLEEP
lv2_obj::sleep(ppu);
@ -2023,7 +2023,7 @@ error_code raw_spu_create_interrupt_tag(u32 id, u32 class_id, u32 /*hwthread*/,
auto& int_ctrl = thread->int_ctrl[class_id];
if (int_ctrl.tag && int_ctrl.tag->exists)
if (lv2_obj::check(int_ctrl.tag))
{
error = CELL_EAGAIN;
return result;

View File

@ -88,6 +88,12 @@ public:
// Existence validation (workaround for shared-ptr ref-counting)
atomic_t<u32> exists = 0;
template <typename Ptr>
static bool check(Ptr&& ptr)
{
return ptr && ptr->exists;
}
static std::string name64(u64 name_u64)
{
const auto ptr = reinterpret_cast<const char*>(&name_u64);

View File

@ -83,7 +83,7 @@ error_code sys_timer_destroy(ppu_thread& ppu, u32 timer_id)
const auto timer = idm::withdraw<lv2_obj, lv2_timer>(timer_id, [&](lv2_timer& timer) -> CellError
{
if (reader_lock lock(timer.mutex); lv2_event_queue::check(timer.port))
if (reader_lock lock(timer.mutex); lv2_obj::check(timer.port))
{
return CELL_EISCONN;
}
@ -151,7 +151,7 @@ error_code _sys_timer_start(ppu_thread& ppu, u32 timer_id, u64 base_time, u64 pe
{
std::unique_lock lock(timer.mutex);
if (!lv2_event_queue::check(timer.port))
if (!lv2_obj::check(timer.port))
{
return CELL_ENOTCONN;
}
@ -222,7 +222,7 @@ error_code sys_timer_connect_event_queue(ppu_thread& ppu, u32 timer_id, u32 queu
std::lock_guard lock(timer.mutex);
if (lv2_event_queue::check(timer.port))
if (lv2_obj::check(timer.port))
{
return CELL_EISCONN;
}
@ -260,7 +260,7 @@ error_code sys_timer_disconnect_event_queue(ppu_thread& ppu, u32 timer_id)
timer.state = SYS_TIMER_STATE_STOP;
if (!lv2_event_queue::check(timer.port))
if (!lv2_obj::check(timer.port))
{
return CELL_ENOTCONN;
}

View File

@ -352,7 +352,7 @@ void kernel_explorer::Update()
auto& tag = static_cast<lv2_int_tag&>(obj);
const auto handler = tag.handler.get();
if (handler && handler->exists)
if (lv2_obj::check(handler))
{
add_leaf(node, qstr(fmt::format("Intr Tag 0x%08x, Handler: 0x%08x", id, handler->id)));
break;
@ -379,7 +379,7 @@ void kernel_explorer::Update()
auto& ep = static_cast<lv2_event_port&>(obj);
const auto type = ep.type == SYS_EVENT_PORT_LOCAL ? "LOCAL"sv : "IPC"sv;
if (const auto queue = ep.queue.get(); queue && queue->exists)
if (const auto queue = ep.queue.get(); lv2_obj::check(queue))
{
if (queue == idm::check_unlocked<lv2_obj, lv2_event_queue>(queue->id))
{