Fixing some shutdown code.
This commit is contained in:
@@ -28,11 +28,6 @@ AudioSystem::AudioSystem(Emulator* emulator) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
AudioSystem::~AudioSystem() {
|
AudioSystem::~AudioSystem() {
|
||||||
// TODO(benvanik): thread join.
|
|
||||||
running_ = false;
|
|
||||||
xe_thread_release(thread_);
|
|
||||||
|
|
||||||
xe_run_loop_release(run_loop_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
X_STATUS AudioSystem::Setup() {
|
X_STATUS AudioSystem::Setup() {
|
||||||
@@ -80,13 +75,15 @@ void AudioSystem::ThreadStart() {
|
|||||||
//worker_->Pump();
|
//worker_->Pump();
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
|
|
||||||
|
if (!running_) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Pump audio system.
|
// Pump audio system.
|
||||||
Pump();
|
Pump();
|
||||||
}
|
}
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
Shutdown();
|
|
||||||
|
|
||||||
xe_run_loop_release(run_loop);
|
xe_run_loop_release(run_loop);
|
||||||
|
|
||||||
// TODO(benvanik): call module API to kill?
|
// TODO(benvanik): call module API to kill?
|
||||||
@@ -96,6 +93,11 @@ void AudioSystem::Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AudioSystem::Shutdown() {
|
void AudioSystem::Shutdown() {
|
||||||
|
running_ = false;
|
||||||
|
xe_thread_join(thread_);
|
||||||
|
xe_thread_release(thread_);
|
||||||
|
|
||||||
|
xe_run_loop_release(run_loop_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioSystem::HandlesRegister(uint64_t addr) {
|
bool AudioSystem::HandlesRegister(uint64_t addr) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public:
|
|||||||
cpu::Processor* processor() const { return processor_; }
|
cpu::Processor* processor() const { return processor_; }
|
||||||
|
|
||||||
virtual X_STATUS Setup();
|
virtual X_STATUS Setup();
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
bool HandlesRegister(uint64_t addr);
|
bool HandlesRegister(uint64_t addr);
|
||||||
virtual uint64_t ReadRegister(uint64_t addr);
|
virtual uint64_t ReadRegister(uint64_t addr);
|
||||||
@@ -41,7 +42,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
virtual void Pump() = 0;
|
virtual void Pump() = 0;
|
||||||
virtual void Shutdown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ThreadStartThunk(AudioSystem* this_ptr) {
|
static void ThreadStartThunk(AudioSystem* this_ptr) {
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ public:
|
|||||||
NopAudioSystem(Emulator* emulator);
|
NopAudioSystem(Emulator* emulator);
|
||||||
virtual ~NopAudioSystem();
|
virtual ~NopAudioSystem();
|
||||||
|
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
virtual void Pump();
|
virtual void Pump();
|
||||||
virtual void Shutdown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ int xe_thread_start(xe_thread_ref thread) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xe_thread_join(xe_thread_ref thread) {
|
||||||
|
HANDLE thread_handle = (HANDLE)thread->handle;
|
||||||
|
WaitForSingleObject(thread_handle, INFINITE);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void* xe_thread_callback_pthreads(void* param) {
|
static void* xe_thread_callback_pthreads(void* param) {
|
||||||
@@ -137,4 +142,8 @@ int xe_thread_start(xe_thread_ref thread) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xe_thread_join(xe_thread_ref thread) {
|
||||||
|
pthread_join((pthread_t)thread->handle, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ xe_thread_ref xe_thread_retain(xe_thread_ref thread);
|
|||||||
void xe_thread_release(xe_thread_ref thread);
|
void xe_thread_release(xe_thread_ref thread);
|
||||||
|
|
||||||
int xe_thread_start(xe_thread_ref thread);
|
int xe_thread_start(xe_thread_ref thread);
|
||||||
|
void xe_thread_join(xe_thread_ref thread);
|
||||||
|
|
||||||
|
|
||||||
#endif // XENIA_CORE_THREAD_H_
|
#endif // XENIA_CORE_THREAD_H_
|
||||||
|
|||||||
@@ -56,8 +56,13 @@ Emulator::~Emulator() {
|
|||||||
delete file_system_;
|
delete file_system_;
|
||||||
|
|
||||||
delete input_system_;
|
delete input_system_;
|
||||||
|
|
||||||
|
// Give the systems time to shutdown before we delete them.
|
||||||
|
graphics_system_->Shutdown();
|
||||||
|
audio_system_->Shutdown();
|
||||||
delete graphics_system_;
|
delete graphics_system_;
|
||||||
delete audio_system_;
|
delete audio_system_;
|
||||||
|
|
||||||
delete processor_;
|
delete processor_;
|
||||||
|
|
||||||
delete debug_server_;
|
delete debug_server_;
|
||||||
|
|||||||
@@ -37,9 +37,6 @@ D3D11GraphicsSystem::D3D11GraphicsSystem(Emulator* emulator) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
D3D11GraphicsSystem::~D3D11GraphicsSystem() {
|
D3D11GraphicsSystem::~D3D11GraphicsSystem() {
|
||||||
XESAFERELEASE(device_);
|
|
||||||
XESAFERELEASE(dxgi_factory_);
|
|
||||||
delete window_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D11GraphicsSystem::Initialize() {
|
void D3D11GraphicsSystem::Initialize() {
|
||||||
@@ -50,13 +47,13 @@ void D3D11GraphicsSystem::Initialize() {
|
|||||||
|
|
||||||
timer_queue_ = CreateTimerQueue();
|
timer_queue_ = CreateTimerQueue();
|
||||||
CreateTimerQueueTimer(
|
CreateTimerQueueTimer(
|
||||||
&vsync_timer_,
|
&vsync_timer_,
|
||||||
timer_queue_,
|
timer_queue_,
|
||||||
(WAITORTIMERCALLBACK)D3D11GraphicsSystemVsyncCallback,
|
(WAITORTIMERCALLBACK)D3D11GraphicsSystemVsyncCallback,
|
||||||
this,
|
this,
|
||||||
16,
|
16,
|
||||||
100,
|
100,
|
||||||
WT_EXECUTEINTIMERTHREAD);
|
WT_EXECUTEINTIMERTHREAD);
|
||||||
|
|
||||||
// Create DXGI factory so we can get a swap chain/etc.
|
// Create DXGI factory so we can get a swap chain/etc.
|
||||||
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1),
|
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1),
|
||||||
@@ -158,6 +155,8 @@ void D3D11GraphicsSystem::Pump() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void D3D11GraphicsSystem::Shutdown() {
|
void D3D11GraphicsSystem::Shutdown() {
|
||||||
|
GraphicsSystem::Shutdown();
|
||||||
|
|
||||||
if (vsync_timer_) {
|
if (vsync_timer_) {
|
||||||
DeleteTimerQueueTimer(timer_queue_, vsync_timer_, NULL);
|
DeleteTimerQueueTimer(timer_queue_, vsync_timer_, NULL);
|
||||||
}
|
}
|
||||||
@@ -165,7 +164,10 @@ void D3D11GraphicsSystem::Shutdown() {
|
|||||||
DeleteTimerQueueEx(timer_queue_, NULL);
|
DeleteTimerQueueEx(timer_queue_, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(benvanik): release D3D stuff here?
|
XESAFERELEASE(device_);
|
||||||
|
device_ = 0;
|
||||||
GraphicsSystem::Shutdown();
|
XESAFERELEASE(dxgi_factory_);
|
||||||
|
dxgi_factory_ = 0;
|
||||||
|
delete window_;
|
||||||
|
window_ = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ public:
|
|||||||
D3D11GraphicsSystem(Emulator* emulator);
|
D3D11GraphicsSystem(Emulator* emulator);
|
||||||
virtual ~D3D11GraphicsSystem();
|
virtual ~D3D11GraphicsSystem();
|
||||||
|
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
virtual void Pump();
|
virtual void Pump();
|
||||||
virtual void Shutdown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IDXGIFactory1* dxgi_factory_;
|
IDXGIFactory1* dxgi_factory_;
|
||||||
|
|||||||
@@ -33,14 +33,6 @@ GraphicsSystem::GraphicsSystem(Emulator* emulator) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
GraphicsSystem::~GraphicsSystem() {
|
GraphicsSystem::~GraphicsSystem() {
|
||||||
// TODO(benvanik): thread join.
|
|
||||||
running_ = false;
|
|
||||||
xe_thread_release(thread_);
|
|
||||||
|
|
||||||
// TODO(benvanik): worker join/etc.
|
|
||||||
delete worker_;
|
|
||||||
|
|
||||||
xe_run_loop_release(run_loop_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
X_STATUS GraphicsSystem::Setup() {
|
X_STATUS GraphicsSystem::Setup() {
|
||||||
@@ -90,13 +82,15 @@ void GraphicsSystem::ThreadStart() {
|
|||||||
// Pump worker.
|
// Pump worker.
|
||||||
worker_->Pump();
|
worker_->Pump();
|
||||||
|
|
||||||
|
if (!running_) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Pump graphics system.
|
// Pump graphics system.
|
||||||
Pump();
|
Pump();
|
||||||
}
|
}
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
Shutdown();
|
|
||||||
|
|
||||||
xe_run_loop_release(run_loop);
|
xe_run_loop_release(run_loop);
|
||||||
|
|
||||||
// TODO(benvanik): call module API to kill?
|
// TODO(benvanik): call module API to kill?
|
||||||
@@ -106,6 +100,13 @@ void GraphicsSystem::Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsSystem::Shutdown() {
|
void GraphicsSystem::Shutdown() {
|
||||||
|
running_ = false;
|
||||||
|
xe_thread_join(thread_);
|
||||||
|
xe_thread_release(thread_);
|
||||||
|
|
||||||
|
delete worker_;
|
||||||
|
|
||||||
|
xe_run_loop_release(run_loop_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsSystem::SetInterruptCallback(uint32_t callback,
|
void GraphicsSystem::SetInterruptCallback(uint32_t callback,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
cpu::Processor* processor() const { return processor_; }
|
cpu::Processor* processor() const { return processor_; }
|
||||||
|
|
||||||
virtual X_STATUS Setup();
|
virtual X_STATUS Setup();
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
void SetInterruptCallback(uint32_t callback, uint32_t user_data);
|
void SetInterruptCallback(uint32_t callback, uint32_t user_data);
|
||||||
void InitializeRingBuffer(uint32_t ptr, uint32_t page_count);
|
void InitializeRingBuffer(uint32_t ptr, uint32_t page_count);
|
||||||
@@ -51,7 +52,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
virtual void Pump() = 0;
|
virtual void Pump() = 0;
|
||||||
virtual void Shutdown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ThreadStartThunk(GraphicsSystem* this_ptr) {
|
static void ThreadStartThunk(GraphicsSystem* this_ptr) {
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ public:
|
|||||||
NopGraphicsSystem(Emulator* emulator);
|
NopGraphicsSystem(Emulator* emulator);
|
||||||
virtual ~NopGraphicsSystem();
|
virtual ~NopGraphicsSystem();
|
||||||
|
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
virtual void Pump();
|
virtual void Pump();
|
||||||
virtual void Shutdown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HANDLE timer_queue_;
|
HANDLE timer_queue_;
|
||||||
|
|||||||
Reference in New Issue
Block a user