Fix integer overflow in scheduling.

This commit is contained in:
Henrik Rydgard 2013-01-05 22:44:30 +01:00
parent b72ac7d7f0
commit 6ecf2d235c
4 changed files with 23 additions and 18 deletions

View File

@ -194,7 +194,7 @@ u64 GetIdleTicks()
// This is to be called when outside threads, such as the graphics thread, wants to
// schedule things to be executed on the main thread.
void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata)
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata)
{
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
Event *ne = GetNewTsEvent();
@ -253,7 +253,7 @@ void AddEventToQueue(Event* ne)
// This must be run ONLY from within the cpu thread
// cyclesIntoFuture may be VERY inaccurate if called from anything else
// than Advance
void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata)
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata)
{
Event *ne = GetNewEvent();
ne->userdata = userdata;

View File

@ -39,31 +39,35 @@
//const int CPU_HZ = 222000000;
extern int CPU_HZ;
inline int msToCycles(int ms) {
inline s64 msToCycles(int ms) {
return CPU_HZ / 1000 * ms;
}
inline int msToCycles(float ms) {
return (int)(CPU_HZ * ms * (0.001f));
inline s64 msToCycles(float ms) {
return (s64)(CPU_HZ * ms * (0.001f));
}
inline int msToCycles(double ms) {
return (int)(CPU_HZ * ms * (0.001));
inline s64 msToCycles(double ms) {
return (s64)(CPU_HZ * ms * (0.001));
}
inline int usToCycles(float us) {
return (int)(CPU_HZ * us * (0.000001f));
inline s64 usToCycles(float us) {
return (s64)(CPU_HZ * us * (0.000001f));
}
inline int usToCycles(int us) {
return (int)(CPU_HZ / 1000000 * us);
inline s64 usToCycles(int us) {
return (CPU_HZ / 1000000 * (s64)us);
}
inline u64 usToCycles(u64 us) {
return (u64)(CPU_HZ / 1000000ULL * us);
inline s64 usToCycles(s64 us) {
return (CPU_HZ / 1000000 * us);
}
inline u64 cyclesToUs(u64 cycles) {
inline s64 usToCycles(u64 us) {
return (s64)(CPU_HZ / 1000000 * us);
}
inline s64 cyclesToUs(s64 cycles) {
return cycles / (CPU_HZ / 1000000);
}
@ -85,8 +89,8 @@ namespace CoreTiming
// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk,
// when we implement state saves.
void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata=0);
void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata=0);
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata=0);
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata=0);
void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata=0);
u64 UnscheduleEvent(int event_type, u64 userdata);

View File

@ -1024,7 +1024,8 @@ void hleScheduledWakeup(u64 userdata, int cyclesLate)
void __KernelScheduleWakeup(SceUID threadID, int usFromNow)
{
CoreTiming::ScheduleEvent(usToCycles(usFromNow), eventScheduledWakeup, threadID);
s64 cycles = usToCycles(usFromNow);
CoreTiming::ScheduleEvent(cycles, eventScheduledWakeup, threadID);
}
void __KernelCancelWakeup(SceUID threadID)

@ -1 +1 @@
Subproject commit 3e41f389df00ea2aaeb338f8ebad030397386200
Subproject commit dddc3db6f1b3d18c9aac9bf998225c3bc1b8185a