1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

SQueue renamed and moved

This commit is contained in:
Nekotekina 2014-12-25 01:24:17 +03:00
parent 69388f032e
commit 7613d749ec
23 changed files with 311 additions and 254 deletions

View File

@ -1,118 +0,0 @@
#pragma once
static const volatile bool sq_no_wait = true;
template<typename T, u32 SQSize = 666>
class SQueue
{
mutable std::mutex m_mutex;
u32 m_pos;
u32 m_count;
T m_data[SQSize];
public:
SQueue()
: m_pos(0)
, m_count(0)
{
}
u32 GetSize() const
{
return SQSize;
}
bool IsFull() const volatile
{
return m_count == SQSize;
}
bool Push(const T& data, const volatile bool* do_exit)
{
while (true)
{
if (m_count >= SQSize)
{
if (Emu.IsStopped() || (do_exit && *do_exit))
{
return false;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
continue;
}
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_count >= SQSize) continue;
m_data[(m_pos + m_count++) % SQSize] = data;
return true;
}
}
}
bool Pop(T& data, const volatile bool* do_exit)
{
while (true)
{
if (!m_count)
{
if (Emu.IsStopped() || (do_exit && *do_exit))
{
return false;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
continue;
}
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!m_count) continue;
data = m_data[m_pos];
m_pos = (m_pos + 1) % SQSize;
m_count--;
return true;
}
}
}
void Clear()
{
std::lock_guard<std::mutex> lock(m_mutex);
m_count = 0;
}
bool Peek(T& data, const volatile bool* do_exit, u32 pos = 0)
{
while (true)
{
if (m_count <= pos)
{
if (Emu.IsStopped() || (do_exit && *do_exit))
{
return false;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
continue;
}
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_count > pos)
{
break;
}
}
}
data = m_data[(m_pos + pos) % SQSize];
return true;
}
};

View File

@ -1,4 +1,5 @@
#pragma once
#include "Emu/Memory/atomic_type.h"
static std::thread::id main_thread;
@ -71,33 +72,6 @@ public:
bool joinable() const;
};
class s_mutex_t
{
};
class s_shared_mutex_t
{
};
class s_cond_var_t
{
//public:
// s_cond_var_t();
// ~s_cond_var_t();
//
// s_cond_var_t(s_cond_var_t& right) = delete;
// s_cond_var_t& operator = (s_cond_var_t& right) = delete;
//
// void wait();
// void wait_for();
//
// void notify();
// void notify_all();
};
class slw_mutex_t
{
@ -173,3 +147,227 @@ public:
// signal all threads waiting on waiter_op() with the same signal_id (signaling only hints those threads that corresponding conditions are *probably* met)
void notify(u64 signal_id);
};
template<typename T, u32 sq_size = 256>
class squeue_t
{
struct squeue_sync_var_t
{
struct
{
u32 position : 31;
u32 read_lock : 1;
};
struct
{
u32 count : 31;
u32 write_lock : 1;
};
};
atomic_le_t<squeue_sync_var_t> m_sync;
mutable std::mutex m_rcv_mutex, m_wcv_mutex;
mutable std::condition_variable m_rcv, m_wcv;
T m_data[sq_size];
public:
squeue_t()
{
m_sync.write_relaxed({});
}
u32 get_max_size() const
{
return sq_size;
}
bool is_full() const volatile
{
return m_sync.read_relaxed().count == sq_size;
}
bool push(const T& data, const volatile bool* do_exit = nullptr)
{
u32 pos = 0;
while (!m_sync.atomic_op_sync(true, [&pos](squeue_sync_var_t& sync) -> bool
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
if (sync.write_lock || sync.count == sq_size)
{
return false;
}
sync.write_lock = 1;
pos = sync.position + sync.count;
return true;
}))
{
if (Emu.IsStopped() || (do_exit && *do_exit))
{
return false;
}
std::unique_lock<std::mutex> wcv_lock(m_wcv_mutex);
m_wcv.wait_for(wcv_lock, std::chrono::milliseconds(1));
}
m_data[pos >= sq_size ? pos - sq_size : pos] = data;
m_sync.atomic_op([](squeue_sync_var_t& sync)
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
assert(sync.write_lock);
sync.write_lock = 0;
sync.count++;
});
m_rcv.notify_one();
m_wcv.notify_one();
return true;
}
bool try_push(const T& data)
{
static const volatile bool no_wait = true;
return push(data, &no_wait);
}
bool pop(T& data, const volatile bool* do_exit = nullptr)
{
u32 pos = 0;
while (!m_sync.atomic_op_sync(true, [&pos](squeue_sync_var_t& sync) -> bool
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
if (sync.read_lock || !sync.count)
{
return false;
}
sync.read_lock = 1;
pos = sync.position;
return true;
}))
{
if (Emu.IsStopped() || (do_exit && *do_exit))
{
return false;
}
std::unique_lock<std::mutex> rcv_lock(m_rcv_mutex);
m_rcv.wait_for(rcv_lock, std::chrono::milliseconds(1));
}
data = m_data[pos];
m_sync.atomic_op([](squeue_sync_var_t& sync)
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
assert(sync.read_lock);
sync.read_lock = 0;
sync.position++;
sync.count--;
if (sync.position == sq_size)
{
sync.position = 0;
}
});
m_rcv.notify_one();
m_wcv.notify_one();
return true;
}
bool try_pop(T& data)
{
static const volatile bool no_wait = true;
return pop(data, &no_wait);
}
void clear()
{
while (!m_sync.atomic_op_sync(true, [](squeue_sync_var_t& sync) -> bool
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
if (sync.read_lock || sync.write_lock)
{
return false;
}
sync.read_lock = 1;
sync.write_lock = 1;
return true;
}))
{
std::unique_lock<std::mutex> rcv_lock(m_rcv_mutex);
m_rcv.wait_for(rcv_lock, std::chrono::milliseconds(1));
}
m_sync.exchange({});
m_wcv.notify_one();
m_rcv.notify_one();
}
bool peek(T& data, u32 start_pos = 0, const volatile bool* do_exit = nullptr)
{
assert(start_pos < sq_size);
u32 pos = 0;
while (!m_sync.atomic_op_sync(true, [&pos, start_pos](squeue_sync_var_t& sync) -> bool
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
if (sync.read_lock || sync.count <= start_pos)
{
return false;
}
sync.read_lock = 1;
pos = sync.position + start_pos;
return true;
}))
{
if (Emu.IsStopped() || (do_exit && *do_exit))
{
return false;
}
std::unique_lock<std::mutex> rcv_lock(m_rcv_mutex);
m_rcv.wait_for(rcv_lock, std::chrono::milliseconds(1));
}
data = m_data[pos >= sq_size ? pos - sq_size : pos];
m_sync.atomic_op([](squeue_sync_var_t& sync)
{
assert(sync.count <= sq_size);
assert(sync.position < sq_size);
assert(sync.read_lock);
sync.read_lock = 0;
});
m_rcv.notify_one();
return true;
}
bool try_peek(T& data, u32 start_pos = 0)
{
static const volatile bool no_wait = true;
return peek(data, start_pos, &no_wait);
}
};

View File

@ -4,7 +4,6 @@
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/IdManager.h"
#include "Emu/CPU/CPUThreadManager.h"
@ -731,7 +730,7 @@ void SPUThread::WriteChannel(u32 ch, const u128& r)
ef->flags |= (u64)1 << flag;
if (u32 target = ef->check())
{
ef->signal.Push(target, nullptr);
ef->signal.push(target);
}
SPU.In_MBox.PushUncond(CELL_OK);
return;
@ -771,7 +770,7 @@ void SPUThread::WriteChannel(u32 ch, const u128& r)
ef->flags |= (u64)1 << flag;
if (u32 target = ef->check())
{
ef->signal.Push(target, nullptr);
ef->signal.push(target);
}
return;
}

View File

@ -89,7 +89,7 @@ AudioDecoder::~AudioDecoder()
{
// TODO: check finalization
AdecFrame af;
while (frames.Pop(af, &sq_no_wait))
while (frames.try_pop(af))
{
av_frame_unref(af.data);
av_frame_free(&af.data);
@ -151,7 +151,7 @@ next:
if (adec.reader.size < (u32)buf_size /*&& !adec.just_started*/)
{
AdecTask task;
if (!adec.job.Peek(task, &adec.is_closed))
if (!adec.job.peek(task, 0, &adec.is_closed))
{
if (Emu.IsStopped()) cellAdec->Warning("adecRawRead() aborted");
return 0;
@ -176,7 +176,7 @@ next:
adec.cbFunc.call(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, adec.task.au.auInfo_addr, adec.cbArg);
adec.job.Pop(adec.task, nullptr);
adec.job.pop(adec.task);
adec.reader.addr = adec.task.au.addr;
adec.reader.size = adec.task.au.size;
@ -245,7 +245,7 @@ u32 adecOpen(AudioDecoder* data)
break;
}
if (!adec.job.Pop(task, &adec.is_closed))
if (!adec.job.pop(task, &adec.is_closed))
{
break;
}
@ -451,7 +451,7 @@ u32 adecOpen(AudioDecoder* data)
//LOG_NOTICE(HLE, "got audio frame (pts=0x%llx, nb_samples=%d, ch=%d, sample_rate=%d, nbps=%d)",
//frame.pts, frame.data->nb_samples, frame.data->channels, frame.data->sample_rate, nbps);
if (adec.frames.Push(frame, &adec.is_closed))
if (adec.frames.push(frame, &adec.is_closed))
{
frame.data = nullptr; // to prevent destruction
adec.cbFunc.call(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg);
@ -562,7 +562,7 @@ int cellAdecClose(u32 handle)
}
adec->is_closed = true;
adec->job.Push(AdecTask(adecClose), &sq_no_wait);
adec->job.try_push(AdecTask(adecClose));
while (!adec->is_finished)
{
@ -627,7 +627,7 @@ int cellAdecStartSeq(u32 handle, u32 param_addr)
}
}
adec->job.Push(task, &adec->is_closed);
adec->job.push(task, &adec->is_closed);
return CELL_OK;
}
@ -641,7 +641,7 @@ int cellAdecEndSeq(u32 handle)
return CELL_ADEC_ERROR_ARG;
}
adec->job.Push(AdecTask(adecEndSeq), &adec->is_closed);
adec->job.push(AdecTask(adecEndSeq), &adec->is_closed);
return CELL_OK;
}
@ -663,7 +663,7 @@ int cellAdecDecodeAu(u32 handle, vm::ptr<CellAdecAuInfo> auInfo)
task.au.userdata = auInfo->userData;
//cellAdec->Notice("cellAdecDecodeAu(): addr=0x%x, size=0x%x, pts=0x%llx", task.au.addr, task.au.size, task.au.pts);
adec->job.Push(task, &adec->is_closed);
adec->job.push(task, &adec->is_closed);
return CELL_OK;
}
@ -678,7 +678,7 @@ int cellAdecGetPcm(u32 handle, vm::ptr<float> outBuffer)
}
AdecFrame af;
if (!adec->frames.Pop(af, &sq_no_wait))
if (!adec->frames.try_pop(af))
{
//std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
return CELL_ADEC_ERROR_EMPTY;
@ -792,7 +792,7 @@ int cellAdecGetPcmItem(u32 handle, vm::ptr<u32> pcmItem_ptr)
}
AdecFrame af;
if (!adec->frames.Peek(af, &sq_no_wait))
if (!adec->frames.try_peek(af))
{
//std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
return CELL_ADEC_ERROR_EMPTY;

View File

@ -1,7 +1,5 @@
#pragma once
#include "Utilities/SQueue.h"
// Error Codes
enum
{
@ -1101,7 +1099,7 @@ static_assert(sizeof(OMAHeader) == 96, "Wrong OMAHeader size");
class AudioDecoder
{
public:
SQueue<AdecTask> job;
squeue_t<AdecTask> job;
u32 id;
volatile bool is_closed;
volatile bool is_finished;
@ -1128,7 +1126,7 @@ public:
} reader;
SQueue<AdecFrame> frames;
squeue_t<AdecFrame> frames;
const AudioCodecType type;
const u32 memAddr;

View File

@ -5,7 +5,6 @@
#include "Emu/Memory/atomic_type.h"
#include "rpcs3/Ini.h"
#include "Utilities/SQueue.h"
#include "Emu/SysCalls/lv2/sleep_queue_type.h"
#include "Emu/SysCalls/lv2/sys_time.h"
#include "Emu/SysCalls/lv2/sys_event.h"
@ -77,11 +76,8 @@ int cellAudioInit()
oal_buffer_float[i] = std::unique_ptr<float[]>(new float[oal_buffer_size] {} );
}
SQueue<s16*, 31> queue;
queue.Clear();
SQueue<float*, 31> queue_float;
queue_float.Clear();
squeue_t<s16*, 31> queue;
squeue_t<float*, 31> queue_float;
std::vector<u64> keys;
@ -108,9 +104,9 @@ int cellAudioInit()
float* oal_buffer_float = nullptr;
if (g_is_u16)
queue.Pop(oal_buffer, nullptr);
queue.pop(oal_buffer);
else
queue_float.Pop(oal_buffer_float, nullptr);
queue_float.pop(oal_buffer_float);
if (g_is_u16)
{
@ -373,9 +369,9 @@ int cellAudioInit()
if(m_audio_out)
{
if (g_is_u16)
queue.Push(&oal_buffer[oal_pos][0], nullptr);
queue.push(&oal_buffer[oal_pos][0]);
queue_float.Push(&oal_buffer_float[oal_pos][0], nullptr);
queue_float.push(&oal_buffer_float[oal_pos][0]);
}
oal_buffer_offset = 0;
@ -441,8 +437,8 @@ int cellAudioInit()
}
cellAudio->Notice("Audio thread ended");
abort:
queue.Push(nullptr, nullptr);
queue_float.Push(nullptr, nullptr);
queue.push(nullptr);
queue_float.push(nullptr);
if(do_dump)
m_dump.Finalize();

View File

@ -106,13 +106,13 @@ bool ElementaryStream::is_full(u32 space)
{
if (released < put_count)
{
if (entries.IsFull())
if (entries.is_full())
{
return true;
}
u32 first = 0;
if (!entries.Peek(first, &dmux->is_closed) || !first)
if (!entries.peek(first, 0, &dmux->is_closed) || !first)
{
assert(!"es::is_full() error: entries.Peek() failed");
return false;
@ -188,7 +188,7 @@ void ElementaryStream::push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool ra
put_count++;
}
if (!entries.Push(addr, &dmux->is_closed))
if (!entries.push(addr, &dmux->is_closed))
{
assert(!"es::push_au() error: entries.Push() failed");
}
@ -222,7 +222,7 @@ bool ElementaryStream::release()
}
u32 addr = 0;
if (!entries.Pop(addr, &dmux->is_closed) || !addr)
if (!entries.pop(addr, &dmux->is_closed) || !addr)
{
cellDmux->Error("es::release() error: entries.Pop() failed");
Emu.Pause();
@ -248,7 +248,7 @@ bool ElementaryStream::peek(u32& out_data, bool no_ex, u32& out_spec, bool updat
}
u32 addr = 0;
if (!entries.Peek(addr, &dmux->is_closed, got_count - released) || !addr)
if (!entries.peek(addr, got_count - released, &dmux->is_closed) || !addr)
{
cellDmux->Error("es::peek() error: entries.Peek() failed");
Emu.Pause();
@ -269,7 +269,7 @@ void ElementaryStream::reset()
{
std::lock_guard<std::mutex> lock(m_mutex);
put = memAddr;
entries.Clear();
entries.clear();
put_count = 0;
got_count = 0;
released = 0;
@ -337,7 +337,7 @@ u32 dmuxOpen(Demuxer* data)
break;
}
if (!dmux.job.Peek(task, &sq_no_wait) && dmux.is_running && stream.addr)
if (!dmux.job.try_peek(task) && dmux.is_running && stream.addr)
{
// default task (demuxing) (if there is no other work)
be_t<u32> code;
@ -603,7 +603,7 @@ u32 dmuxOpen(Demuxer* data)
}
// wait for task if no work
if (!dmux.job.Pop(task, &dmux.is_closed))
if (!dmux.job.pop(task, &dmux.is_closed))
{
break; // Emu is stopped
}
@ -859,7 +859,7 @@ int cellDmuxClose(u32 demuxerHandle)
}
dmux->is_closed = true;
dmux->job.Push(DemuxerTask(dmuxClose), &sq_no_wait);
dmux->job.try_push(DemuxerTask(dmuxClose));
while (!dmux->is_finished)
{
@ -901,7 +901,7 @@ int cellDmuxSetStream(u32 demuxerHandle, const u32 streamAddress, u32 streamSize
info.discontinuity = discontinuity;
info.userdata = userData;
dmux->job.Push(task, &dmux->is_closed);
dmux->job.push(task, &dmux->is_closed);
return CELL_OK;
}
@ -915,7 +915,7 @@ int cellDmuxResetStream(u32 demuxerHandle)
return CELL_DMUX_ERROR_ARG;
}
dmux->job.Push(DemuxerTask(dmuxResetStream), &dmux->is_closed);
dmux->job.push(DemuxerTask(dmuxResetStream), &dmux->is_closed);
return CELL_OK;
}
@ -929,7 +929,7 @@ int cellDmuxResetStreamAndWaitDone(u32 demuxerHandle)
return CELL_DMUX_ERROR_ARG;
}
dmux->job.Push(DemuxerTask(dmuxResetStreamAndWaitDone), &dmux->is_closed);
dmux->job.push(DemuxerTask(dmuxResetStreamAndWaitDone), &dmux->is_closed);
while (dmux->is_running && !dmux->is_closed) // TODO: ensure that it is safe
{
if (Emu.IsStopped())
@ -1005,7 +1005,7 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr<const CellCodecEsFilterId> esFil
task.es.es = id;
task.es.es_ptr = es.get();
dmux->job.Push(task, &dmux->is_closed);
dmux->job.push(task, &dmux->is_closed);
return CELL_OK;
}
@ -1023,7 +1023,7 @@ int cellDmuxDisableEs(u32 esHandle)
task.es.es = esHandle;
task.es.es_ptr = es.get();
es->dmux->job.Push(task, &es->dmux->is_closed);
es->dmux->job.push(task, &es->dmux->is_closed);
return CELL_OK;
}
@ -1041,7 +1041,7 @@ int cellDmuxResetEs(u32 esHandle)
task.es.es = esHandle;
task.es.es_ptr = es.get();
es->dmux->job.Push(task, &es->dmux->is_closed);
es->dmux->job.push(task, &es->dmux->is_closed);
return CELL_OK;
}
@ -1168,7 +1168,7 @@ int cellDmuxFlushEs(u32 esHandle)
task.es.es = esHandle;
task.es.es_ptr = es.get();
es->dmux->job.Push(task, &es->dmux->is_closed);
es->dmux->job.push(task, &es->dmux->is_closed);
return CELL_OK;
}

View File

@ -1,7 +1,5 @@
#pragma once
#include "Utilities/SQueue.h"
// align size or address to 128
#define a128(x) ((x + 127) & (~127))
@ -400,7 +398,7 @@ struct DemuxerTask
class Demuxer
{
public:
SQueue<DemuxerTask, 32> job;
squeue_t<DemuxerTask, 32> job;
const u32 memAddr;
const u32 memSize;
const vm::ptr<CellDmuxCbMsg> cbFunc;
@ -429,7 +427,7 @@ class ElementaryStream
{
std::mutex m_mutex;
SQueue<u32> entries; // AU starting addresses
squeue_t<u32> entries; // AU starting addresses
u32 put_count; // number of AU written
u32 got_count; // number of AU obtained by GetAu(Ex)
u32 released; // number of AU released

View File

@ -4,7 +4,6 @@
#include "Emu/SysCalls/Modules.h"
#include "Emu/SysCalls/CB_FUNC.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/Cell/SPUThread.h"
#include "Emu/SysCalls/lv2/sleep_queue_type.h"

View File

@ -3,7 +3,6 @@
#include "Emu/System.h"
#include "Emu/SysCalls/Modules.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/SysCalls/lv2/sleep_queue_type.h"
#include "Emu/SysCalls/lv2/sys_lwmutex.h"

View File

@ -93,7 +93,7 @@ VideoDecoder::~VideoDecoder()
{
// TODO: check finalization
VdecFrame vf;
while (frames.Pop(vf, &sq_no_wait))
while (frames.try_pop(vf))
{
av_frame_unref(vf.data);
av_frame_free(&vf.data);
@ -124,7 +124,7 @@ next:
if (vdec.reader.size < (u32)buf_size /*&& !vdec.just_started*/)
{
VdecTask task;
if (!vdec.job.Peek(task, &vdec.is_closed))
if (!vdec.job.peek(task, 0, &vdec.is_closed))
{
if (Emu.IsStopped()) cellVdec->Warning("vdecRead() aborted");
return 0;
@ -149,7 +149,7 @@ next:
vdec.cbFunc.call(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg);
vdec.job.Pop(vdec.task, nullptr);
vdec.job.pop(vdec.task);
vdec.reader.addr = vdec.task.addr;
vdec.reader.size = vdec.task.size;
@ -235,7 +235,7 @@ u32 vdecOpen(VideoDecoder* data)
break;
}
if (!vdec.job.Pop(task, &vdec.is_closed))
if (!vdec.job.pop(task, &vdec.is_closed))
{
break;
}
@ -512,7 +512,7 @@ u32 vdecOpen(VideoDecoder* data)
//LOG_NOTICE(HLE, "got picture (pts=0x%llx, dts=0x%llx)", frame.pts, frame.dts);
if (vdec.frames.Push(frame, &vdec.is_closed))
if (vdec.frames.push(frame, &vdec.is_closed))
{
frame.data = nullptr; // to prevent destruction
vdec.cbFunc.call(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg);
@ -598,7 +598,7 @@ int cellVdecClose(u32 handle)
}
vdec->is_closed = true;
vdec->job.Push(VdecTask(vdecClose), &sq_no_wait);
vdec->job.try_push(VdecTask(vdecClose));
while (!vdec->is_finished)
{
@ -625,7 +625,7 @@ int cellVdecStartSeq(u32 handle)
return CELL_VDEC_ERROR_ARG;
}
vdec->job.Push(VdecTask(vdecStartSeq), &vdec->is_closed);
vdec->job.push(VdecTask(vdecStartSeq), &vdec->is_closed);
return CELL_OK;
}
@ -639,7 +639,7 @@ int cellVdecEndSeq(u32 handle)
return CELL_VDEC_ERROR_ARG;
}
vdec->job.Push(VdecTask(vdecEndSeq), &vdec->is_closed);
vdec->job.push(VdecTask(vdecEndSeq), &vdec->is_closed);
return CELL_OK;
}
@ -663,7 +663,7 @@ int cellVdecDecodeAu(u32 handle, CellVdecDecodeMode mode, vm::ptr<const CellVdec
task.userData = auInfo->userData;
task.specData = auInfo->codecSpecificData;
vdec->job.Push(task, &vdec->is_closed);
vdec->job.push(task, &vdec->is_closed);
return CELL_OK;
}
@ -678,7 +678,7 @@ int cellVdecGetPicture(u32 handle, vm::ptr<const CellVdecPicFormat> format, vm::
}
VdecFrame vf;
if (!vdec->frames.Pop(vf, &sq_no_wait))
if (!vdec->frames.try_pop(vf))
{
//std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
return CELL_VDEC_ERROR_EMPTY;
@ -734,7 +734,7 @@ int cellVdecGetPicItem(u32 handle, vm::ptr<u32> picItem_ptr)
}
VdecFrame vf;
if (!vdec->frames.Peek(vf, &sq_no_wait))
if (!vdec->frames.try_peek(vf))
{
//std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
return CELL_VDEC_ERROR_EMPTY;
@ -882,7 +882,7 @@ int cellVdecSetFrameRate(u32 handle, CellVdecFrameRate frc)
VdecTask task(vdecSetFrameRate);
task.frc = frc;
vdec->job.Push(task, &vdec->is_closed);
vdec->job.push(task, &vdec->is_closed);
return CELL_OK;
}

View File

@ -1,7 +1,5 @@
#pragma once
#include "Utilities/SQueue.h"
#define a128(x) ((x + 127) & (~127))
// Error Codes
@ -693,7 +691,7 @@ int vdecRead(void* opaque, u8* buf, int buf_size);
class VideoDecoder
{
public:
SQueue<VdecTask> job;
squeue_t<VdecTask> job;
u32 id;
volatile bool is_closed;
volatile bool is_finished;
@ -712,7 +710,7 @@ public:
u32 size;
} reader;
SQueue<VdecFrame> frames;
squeue_t<VdecFrame> frames;
const CellVdecCodecType type;
const u32 profile;

View File

@ -4,7 +4,6 @@
#include "Emu/SysCalls/Modules.h"
#include "Emu/SysCalls/CB_FUNC.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/FS/vfsFile.h"
#include "Emu/SysCalls/lv2/sleep_queue_type.h"

View File

@ -2,8 +2,7 @@
#include "Utilities/Log.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Utilities/Thread.h"
#include "lv2/sleep_queue_type.h"
#include "lv2/sys_lwmutex.h"

View File

@ -6,7 +6,6 @@
#include "Emu/System.h"
#include "ModuleManager.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "lv2/cellFs.h"
#include "lv2/sleep_queue_type.h"

View File

@ -3,7 +3,6 @@
#include "Emu/System.h"
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/CPU/CPUThreadManager.h"
#include "Emu/Cell/PPUThread.h"
@ -78,7 +77,7 @@ s32 sys_cond_signal(u32 cond_id)
if (u32 target = cond->queue.pop(mutex->protocol))
{
cond->signal.Push(target, nullptr);
cond->signal.push(target);
if (Emu.IsStopped())
{
@ -103,7 +102,7 @@ s32 sys_cond_signal_all(u32 cond_id)
while (u32 target = cond->queue.pop(mutex->protocol))
{
cond->signal.Push(target, nullptr);
cond->signal.push(target);
if (Emu.IsStopped())
{
@ -139,7 +138,7 @@ s32 sys_cond_signal_to(u32 cond_id, u32 thread_id)
u32 target = thread_id;
{
cond->signal.Push(target, nullptr);
cond->signal.push(target);
}
if (Emu.IsStopped())
@ -182,7 +181,7 @@ s32 sys_cond_wait(PPUThread& CPU, u32 cond_id, u64 timeout)
while (true)
{
u32 signaled;
if (cond->signal.Peek(signaled, &sq_no_wait) && signaled == tid) // check signaled threads
if (cond->signal.try_peek(signaled) && signaled == tid) // check signaled threads
{
if (mutex->owner.compare_and_swap_test(0, tid)) // try to lock
{
@ -224,6 +223,6 @@ s32 sys_cond_wait(PPUThread& CPU, u32 cond_id, u64 timeout)
}
mutex->recursive_count = old_recursive;
cond->signal.Pop(cond_id /* unused result */, nullptr);
cond->signal.pop(cond_id /* unused result */);
return CELL_OK;
}

View File

@ -15,7 +15,7 @@ struct sys_cond_attribute
struct Cond
{
std::shared_ptr<Mutex> mutex; // associated with mutex
SQueue<u32, 32> signal;
squeue_t<u32, 32> signal;
sleep_queue_t queue;
Cond(std::shared_ptr<Mutex>& mutex, u64 name)

View File

@ -3,7 +3,6 @@
#include "Emu/System.h"
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/CPU/CPUThreadManager.h"
#include "Emu/Cell/PPUThread.h"
@ -182,13 +181,13 @@ s32 sys_event_flag_wait(u32 eflag_id, u64 bitptn, u32 mode, vm::ptr<u64> result,
while (true)
{
u32 signaled;
if (ef->signal.Peek(signaled, &sq_no_wait) && signaled == tid)
if (ef->signal.try_peek(signaled) && signaled == tid)
{
std::lock_guard<std::mutex> lock(ef->mutex);
const u64 flag_set = ef->flags.read_sync();
ef->signal.Pop(signaled, nullptr);
ef->signal.pop(signaled);
for (u32 i = 0; i < ef->waiters.size(); i++)
{
@ -207,7 +206,7 @@ s32 sys_event_flag_wait(u32 eflag_id, u64 bitptn, u32 mode, vm::ptr<u64> result,
if (u32 target = ef->check())
{
ef->signal.Push(target, nullptr);
ef->signal.push(target);
}
if (result)
@ -310,7 +309,7 @@ s32 sys_event_flag_set(u32 eflag_id, u64 bitptn)
ef->flags |= bitptn;
if (u32 target = ef->check())
{
ef->signal.Push(target, nullptr);
ef->signal.push(target);
}
return CELL_OK;
}
@ -346,9 +345,9 @@ s32 sys_event_flag_cancel(u32 eflag_id, vm::ptr<u32> num)
ef->waiters.clear();
}
for (u32 i = 0; i < tids.size(); i++)
for (auto& v : tids)
{
ef->signal.Push(tids[i], nullptr);
ef->signal.push(v);
}
if (Emu.IsStopped())

View File

@ -36,7 +36,7 @@ struct EventFlagWaiter
struct EventFlag
{
atomic_le_t<u64> flags;
SQueue<u32, 32> signal;
squeue_t<u32, 32> signal;
std::mutex mutex; // protects waiters
std::vector<EventFlagWaiter> waiters;

View File

@ -3,7 +3,6 @@
#include "Emu/System.h"
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/Memory/atomic_type.h"
#include "Utilities/SQueue.h"
#include "Emu/Cell/PPUThread.h"
#include "sleep_queue_type.h"
@ -72,7 +71,7 @@ s32 sys_lwcond_signal(vm::ptr<sys_lwcond_t> lwcond)
if (u32 target = lw->queue.pop(mutex->attribute))
{
lw->signal.Push(target, nullptr);
lw->signal.push(target);
if (Emu.IsStopped())
{
@ -98,7 +97,7 @@ s32 sys_lwcond_signal_all(vm::ptr<sys_lwcond_t> lwcond)
while (u32 target = lw->queue.pop(mutex->attribute))
{
lw->signal.Push(target, nullptr);
lw->signal.push(target);
if (Emu.IsStopped())
{
@ -132,7 +131,7 @@ s32 sys_lwcond_signal_to(vm::ptr<sys_lwcond_t> lwcond, u32 ppu_thread_id)
u32 target = ppu_thread_id;
{
lw->signal.Push(target, nullptr);
lw->signal.push(target);
if (Emu.IsStopped())
{
@ -186,7 +185,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
while (true)
{
u32 signaled;
if (lw->signal.Peek(signaled, &sq_no_wait) && signaled == tid_le) // check signaled threads
if (lw->signal.try_peek(signaled) && signaled == tid_le) // check signaled threads
{
s32 res = mutex->lock(tid, timeout ? get_system_time() - time_start : 0); // this is bad
if (res == CELL_OK)
@ -200,34 +199,34 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
{
sys_lwcond.Error("sys_lwcond_wait(id=%d): associated mutex was locked", (u32)lwcond->lwcond_queue);
lw->queue.invalidate(tid_le);
lw->signal.Pop(tid_le /* unused result */, nullptr);
lw->signal.pop(tid_le /* unused result */);
return CELL_OK; // mutex not locked (but already locked in the incorrect way)
}
case static_cast<int>(CELL_ESRCH):
{
sys_lwcond.Error("sys_lwcond_wait(id=%d): associated mutex not found (%d)", (u32)lwcond->lwcond_queue, (u32)mutex->sleep_queue);
lw->queue.invalidate(tid_le);
lw->signal.Pop(tid_le /* unused result */, nullptr);
lw->signal.pop(tid_le /* unused result */);
return CELL_ESRCH; // mutex not locked
}
case static_cast<int>(CELL_ETIMEDOUT):
{
lw->queue.invalidate(tid_le);
lw->signal.Pop(tid_le /* unused result */, nullptr);
lw->signal.pop(tid_le /* unused result */);
return CELL_ETIMEDOUT; // mutex not locked
}
case static_cast<int>(CELL_EINVAL):
{
sys_lwcond.Error("sys_lwcond_wait(id=%d): invalid associated mutex (%d)", (u32)lwcond->lwcond_queue, (u32)mutex->sleep_queue);
lw->queue.invalidate(tid_le);
lw->signal.Pop(tid_le /* unused result */, nullptr);
lw->signal.pop(tid_le /* unused result */);
return CELL_EINVAL; // mutex not locked
}
default:
{
sys_lwcond.Error("sys_lwcond_wait(id=%d): mutex->lock() returned 0x%x", (u32)lwcond->lwcond_queue, res);
lw->queue.invalidate(tid_le);
lw->signal.Pop(tid_le /* unused result */, nullptr);
lw->signal.pop(tid_le /* unused result */);
return CELL_EINVAL; // mutex not locked
}
}
@ -249,6 +248,6 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
}
mutex->recursive_count.exchange(old_recursive);
lw->signal.Pop(tid_le /* unused result */, nullptr);
lw->signal.pop(tid_le /* unused result */);
return CELL_OK;
}

View File

@ -19,7 +19,7 @@ struct sys_lwcond_t
struct Lwcond
{
SQueue<u32, 32> signal;
squeue_t<u32, 32> signal;
sleep_queue_t queue;
Lwcond(u64 name)

View File

@ -277,7 +277,6 @@
<ClInclude Include="..\Utilities\rXml.h" />
<ClInclude Include="..\Utilities\simpleini\ConvertUTF.h" />
<ClInclude Include="..\Utilities\simpleini\SimpleIni.h" />
<ClInclude Include="..\Utilities\SQueue.h" />
<ClInclude Include="..\Utilities\SSemaphore.h" />
<ClInclude Include="..\Utilities\StrFmt.h" />
<ClInclude Include="..\Utilities\Thread.h" />

View File

@ -383,9 +383,6 @@
<ClCompile Include="..\Utilities\StrFmt.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="..\Utilities\Thread.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="Emu\SysCalls\ModuleManager.cpp">
<Filter>Emu\SysCalls</Filter>
</ClCompile>
@ -653,6 +650,9 @@
<ClCompile Include="Emu\SysCalls\lv2\cellFs.cpp">
<Filter>Emu\SysCalls\lv2</Filter>
</ClCompile>
<ClCompile Include="..\Utilities\Thread.cpp">
<Filter>Utilities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Crypto\aes.h">
@ -1009,15 +1009,9 @@
<ClInclude Include="..\Utilities\BEType.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\SQueue.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\StrFmt.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\Thread.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\Timer.h">
<Filter>Utilities</Filter>
</ClInclude>
@ -1261,5 +1255,8 @@
<ClInclude Include="Emu\SysCalls\lv2\cellFs.h">
<Filter>Emu\SysCalls\lv2</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\Thread.h">
<Filter>Utilities</Filter>
</ClInclude>
</ItemGroup>
</Project>