mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-12 04:35:56 +00:00
Equeue: HrTimer fixes (#2987)
* initial changes * tmp * impl * support wait for multiple timers * cleanup
This commit is contained in:
parent
3f40a8d46e
commit
de69f2b40b
2 changed files with 42 additions and 23 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <vector>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include "common/rdtsc.h"
|
||||
#include "common/types.h"
|
||||
|
||||
|
@ -135,6 +136,12 @@ private:
|
|||
};
|
||||
|
||||
class EqueueInternal {
|
||||
struct SmallTimer {
|
||||
SceKernelEvent event;
|
||||
std::chrono::steady_clock::time_point added;
|
||||
std::chrono::microseconds interval;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit EqueueInternal(std::string_view name) : m_name(name) {}
|
||||
|
||||
|
@ -151,13 +158,14 @@ public:
|
|||
int GetTriggeredEvents(SceKernelEvent* ev, int num);
|
||||
|
||||
bool AddSmallTimer(EqueueEvent& event);
|
||||
bool HasSmallTimer() const {
|
||||
return small_timer_event.event.data != 0;
|
||||
bool HasSmallTimer() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return !m_small_timers.empty();
|
||||
}
|
||||
bool RemoveSmallTimer(u64 id) {
|
||||
if (HasSmallTimer() && small_timer_event.event.ident == id) {
|
||||
small_timer_event = {};
|
||||
return true;
|
||||
if (HasSmallTimer()) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return m_small_timers.erase(id) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -170,8 +178,8 @@ private:
|
|||
std::string m_name;
|
||||
std::mutex m_mutex;
|
||||
std::vector<EqueueEvent> m_events;
|
||||
EqueueEvent small_timer_event{};
|
||||
std::condition_variable m_cond;
|
||||
std::unordered_map<u64, SmallTimer> m_small_timers;
|
||||
};
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetEventData(const SceKernelEvent* ev);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue