squeue_t updated

This commit is contained in:
Nekotekina 2015-01-16 20:09:53 +03:00
parent fd06f70387
commit 4dae27c1d4
6 changed files with 58 additions and 25 deletions

View File

@ -717,7 +717,7 @@ void waiter_map_t::notify(u64 signal_id)
}
}
bool squeue_test_exit(const volatile bool* do_exit)
bool squeue_test_exit()
{
return Emu.IsStopped() || (do_exit && *do_exit);
return Emu.IsStopped();
}

View File

@ -162,7 +162,7 @@ public:
void notify(u64 signal_id);
};
bool squeue_test_exit(const volatile bool* do_exit);
bool squeue_test_exit();
template<typename T, u32 sq_size = 256>
class squeue_t
@ -213,7 +213,7 @@ public:
return m_sync.read_relaxed().count == sq_size;
}
bool push(const T& data, const volatile bool* do_exit = nullptr)
bool push(const T& data, const std::function<bool()>& test_exit)
{
u32 pos = 0;
@ -236,7 +236,7 @@ public:
return SQSVR_OK;
}))
{
if (res == SQSVR_FAILED && squeue_test_exit(do_exit))
if (res == SQSVR_FAILED && (test_exit() || squeue_test_exit()))
{
return false;
}
@ -261,14 +261,22 @@ public:
return true;
}
bool try_push(const T& data)
bool push(const T& data, const volatile bool* do_exit)
{
static const volatile bool no_wait = true;
return push(data, &no_wait);
return push(data, [do_exit](){ return do_exit && *do_exit; });
}
bool pop(T& data, const volatile bool* do_exit = nullptr)
bool push(const T& data)
{
return push(data, [](){ return false; });
}
bool try_push(const T& data)
{
return push(data, [](){ return true; });
}
bool pop(T& data, const std::function<bool()>& test_exit)
{
u32 pos = 0;
@ -291,7 +299,7 @@ public:
return SQSVR_OK;
}))
{
if (res == SQSVR_FAILED && squeue_test_exit(do_exit))
if (res == SQSVR_FAILED && (test_exit() || squeue_test_exit()))
{
return false;
}
@ -321,14 +329,22 @@ public:
return true;
}
bool try_pop(T& data)
bool pop(T& data, const volatile bool* do_exit)
{
static const volatile bool no_wait = true;
return pop(data, &no_wait);
return pop(data, [do_exit](){ return do_exit && *do_exit; });
}
bool peek(T& data, u32 start_pos = 0, const volatile bool* do_exit = nullptr)
bool pop(T& data)
{
return pop(data, [](){ return false; });
}
bool try_pop(T& data)
{
return pop(data, [](){ return true; });
}
bool peek(T& data, u32 start_pos, const std::function<bool()>& test_exit)
{
assert(start_pos < sq_size);
u32 pos = 0;
@ -352,7 +368,7 @@ public:
return SQSVR_OK;
}))
{
if (res == SQSVR_FAILED && squeue_test_exit(do_exit))
if (res == SQSVR_FAILED && (test_exit() || squeue_test_exit()))
{
return false;
}
@ -375,11 +391,19 @@ public:
return true;
}
bool peek(T& data, u32 start_pos, const volatile bool* do_exit)
{
return peek(data, start_pos, [do_exit](){ return do_exit && *do_exit; });
}
bool peek(T& data, u32 start_pos = 0)
{
return peek(data, start_pos, [](){ return false; });
}
bool try_peek(T& data, u32 start_pos = 0)
{
static const volatile bool no_wait = true;
return peek(data, start_pos, &no_wait);
return peek(data, start_pos, [](){ return true; });
}
class squeue_data_t

View File

@ -24,4 +24,4 @@ public:
virtual void Close();
virtual void Stop();
virtual void AddData(const void* src, int size);
};
};

View File

@ -15,4 +15,4 @@ public:
virtual void Close() {}
virtual void Stop() {}
virtual void AddData(const void* src, int size) {}
};
};

View File

@ -15,6 +15,7 @@ void XAudio2Thread::Init()
{
HRESULT hr = S_OK;
#if (_WIN32_WINNT < 0x0602)
hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr))
{
@ -22,6 +23,7 @@ void XAudio2Thread::Init()
Emu.Pause();
return;
}
#endif
hr = XAudio2Create(&m_xaudio2_instance, 0, XAUDIO2_DEFAULT_PROCESSOR);
if (FAILED(hr))
@ -50,6 +52,10 @@ void XAudio2Thread::Quit()
m_xaudio2_instance->StopEngine();
m_xaudio2_instance->Release();
m_xaudio2_instance = nullptr;
#if (_WIN32_WINNT < 0x0602)
CoUninitialize();
#endif
}
void XAudio2Thread::Play()
@ -131,4 +137,4 @@ void XAudio2Thread::AddData(const void* src, int size)
Emu.Pause();
}
}
#endif
#endif

View File

@ -84,7 +84,7 @@ int cellAudioInit()
while (g_audio.state.read_relaxed() == AUDIO_STATE_INITIALIZED && !Emu.IsStopped())
{
float* buffer;
if (out_queue.pop(buffer))
if (out_queue.pop(buffer, [](){ return g_audio.state.read_relaxed() != AUDIO_STATE_INITIALIZED; }))
{
if (use_u16)
{
@ -343,7 +343,10 @@ int cellAudioInit()
memset(out_buffer[out_pos].get(), 0, out_buffer_size * sizeof(float));
}
out_queue.push(out_buffer[out_pos].get());
if (!out_queue.push(out_buffer[out_pos].get(), [](){ return g_audio.state.read_relaxed() != AUDIO_STATE_INITIALIZED; }))
{
break;
}
//const u64 stamp2 = get_system_time();