OS X: fix an oversight with the paused state in EmuThread.

This could have caused bugs later down the line.

git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@92220 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
SND\MaddTheSane_cp 2014-11-09 23:01:19 +00:00
parent 969926ecc0
commit d054dad828
2 changed files with 69 additions and 55 deletions

View File

@ -9,6 +9,12 @@
#import <Foundation/Foundation.h>
#include <setjmp.h>
typedef NS_ENUM(char, EmuThreadPauseStatus) {
PauseStateIsNotPaused = 0,
PauseStatePauseRequested,
PauseStateIsPaused
};
@interface EmuThread : NSObject {
jmp_buf restartJmp;
BOOL wasPaused;
@ -29,6 +35,7 @@
+ (void)reset;
+ (BOOL)isPaused;
+ (EmuThreadPauseStatus)pausedState;
+ (BOOL)active;
+ (BOOL)isRunBios;

View File

@ -15,20 +15,22 @@
#include "plugins.h"
#include "misc.h"
typedef NS_OPTIONS(unsigned int, EmulationEvents) {
EMUEVENT_NONE = 0,
EMUEVENT_PAUSE = (1<<0),
EMUEVENT_RESET = (1<<1),
EMUEVENT_STOP = (1<<2)
};
EmuThread *emuThread = nil;
static NSString *defrostPath = nil;
static int safeEvent;
static BOOL paused;
static EmulationEvents safeEvent;
static EmuThreadPauseStatus paused;
static BOOL runbios;
static pthread_cond_t eventCond;
static pthread_mutex_t eventMutex;
#define EMUEVENT_NONE 0
#define EMUEVENT_PAUSE (1<<0)
#define EMUEVENT_RESET (1<<1)
#define EMUEVENT_STOP (1<<2)
@implementation EmuThread
- (void)setUpThread
@ -140,7 +142,7 @@ done:
if (safeEvent & EMUEVENT_STOP) {
/* signify that the emulation has stopped */
emuThread = nil;
paused = NO;
paused = PauseStateIsNotPaused;
/* better unlock the mutex before killing ourself */
pthread_mutex_unlock(&eventMutex);
@ -179,7 +181,7 @@ done:
}
if (safeEvent & EMUEVENT_PAUSE) {
paused = 2;
paused = PauseStateIsPaused;
/* wait until we're signalled */
pthread_cond_wait(&eventCond, &eventMutex);
}
@ -244,7 +246,7 @@ done:
}
safeEvent = EMUEVENT_NONE;
paused = NO;
paused = PauseStateIsNotPaused;
runbios = YES;
if (SysInit() != 0) {
@ -272,12 +274,12 @@ done:
+ (BOOL)pause
{
if (paused || ![EmuThread active])
if (paused != PauseStateIsNotPaused || ![EmuThread active])
return YES;
pthread_mutex_lock(&eventMutex);
safeEvent |= EMUEVENT_PAUSE;
paused = 1;
paused = PauseStatePauseRequested;
pthread_mutex_unlock(&eventMutex);
pthread_cond_broadcast(&eventCond);
@ -287,11 +289,11 @@ done:
+ (BOOL)pauseSafe
{
if ((paused == 2) || ![EmuThread active])
if ((paused == PauseStateIsPaused) || ![EmuThread active])
return YES;
[EmuThread pause];
while ([EmuThread isPaused] != 2)
while ([EmuThread pausedState] != PauseStateIsPaused)
[NSThread sleepUntilDate:[[NSDate date] dateByAddingTimeInterval:0.05]];
return NO;
@ -307,13 +309,13 @@ done:
+ (void)resume
{
if (!paused || ![EmuThread active])
if (paused == PauseStateIsNotPaused || ![EmuThread active])
return;
pthread_mutex_lock(&eventMutex);
safeEvent &= ~EMUEVENT_PAUSE;
paused = NO;
paused = PauseStateIsNotPaused;
pthread_mutex_unlock(&eventMutex);
pthread_cond_broadcast(&eventCond);
@ -344,11 +346,16 @@ done:
return;
}
+ (BOOL)isPaused
+ (EmuThreadPauseStatus)pausedState
{
return paused;
}
+ (BOOL)isPaused
{
return paused != PauseStateIsNotPaused;
}
+ (BOOL)isRunBios
{
return runbios;