Skip to content

Commit

Permalink
Merge 8e1537a into a1189fa
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Feb 9, 2017
2 parents a1189fa + 8e1537a commit 77e1885
Show file tree
Hide file tree
Showing 61 changed files with 799 additions and 651 deletions.
4 changes: 0 additions & 4 deletions Utilities/Thread.cpp
Expand Up @@ -2380,10 +2380,6 @@ void named_thread::start_thread(const std::shared_ptr<void>& _this)
LOG_FATAL(GENERAL, "%s thrown: %s", typeid(e).name(), e.what());
Emu.Pause();
}
catch (EmulationStopped)
{
LOG_NOTICE(GENERAL, "Thread aborted");
}

on_exit();
});
Expand Down
47 changes: 28 additions & 19 deletions rpcs3/Emu/CPU/CPUThread.cpp
Expand Up @@ -2,7 +2,8 @@
#include "Emu/System.h"
#include "CPUThread.h"

#include <mutex>
DECLARE(cpu_thread::g_threads_created){0};
DECLARE(cpu_thread::g_threads_deleted){0};

template<>
void fmt_class_string<cpu_flag>::format(std::string& out, u64 arg)
Expand All @@ -11,15 +12,15 @@ void fmt_class_string<cpu_flag>::format(std::string& out, u64 arg)
{
switch (f)
{
STR_CASE(cpu_flag::stop);
STR_CASE(cpu_flag::exit);
STR_CASE(cpu_flag::suspend);
STR_CASE(cpu_flag::ret);
STR_CASE(cpu_flag::signal);
STR_CASE(cpu_flag::dbg_global_pause);
STR_CASE(cpu_flag::dbg_global_stop);
STR_CASE(cpu_flag::dbg_pause);
STR_CASE(cpu_flag::dbg_step);
case cpu_flag::stop: return "STOP";
case cpu_flag::exit: return "EXIT";
case cpu_flag::suspend: return "s";
case cpu_flag::ret: return "ret";
case cpu_flag::signal: return "sig";
case cpu_flag::dbg_global_pause: return "G.PAUSE";
case cpu_flag::dbg_global_stop: return "G.EXIT";
case cpu_flag::dbg_pause: return "PAUSE";
case cpu_flag::dbg_step: return "STEP";
case cpu_flag::__bitset_enum_max: break;
}

Expand All @@ -41,10 +42,8 @@ void cpu_thread::on_task()

g_tls_current_cpu_thread = this;

Emu.SendDbgCommand(DID_CREATE_THREAD, this);

// Check thread status
while (!test(state & cpu_flag::exit))
while (!test(state, cpu_flag::exit + cpu_flag::dbg_global_stop))
{
// Check stop status
if (!test(state & cpu_flag::stop))
Expand Down Expand Up @@ -79,27 +78,43 @@ void cpu_thread::on_stop()

cpu_thread::~cpu_thread()
{
g_threads_deleted++;
}

cpu_thread::cpu_thread(u32 id)
: id(id)
{
g_threads_created++;
}

bool cpu_thread::check_state()
{
bool cpu_sleep_called = false;

while (true)
{
if (test(state & cpu_flag::exit))
{
return true;
}

if (test(state & cpu_flag::signal) && state.test_and_reset(cpu_flag::signal))
{
cpu_sleep_called = false;
}

if (!test(state & (cpu_state_pause + cpu_flag::dbg_global_stop)))
{
break;
}

if (test(state & cpu_flag::suspend) && !cpu_sleep_called)
{
cpu_sleep();
cpu_sleep_called = true;
continue;
}

thread_ctrl::wait();
}

Expand All @@ -125,12 +140,6 @@ void cpu_thread::run()
notify();
}

void cpu_thread::set_signal()
{
verify("cpu_flag::signal" HERE), !state.test_and_set(cpu_flag::signal);
notify();
}

std::string cpu_thread::dump() const
{
return fmt::format("Type: %s\n" "State: %s\n", typeid(*this).name(), state.load());
Expand Down
14 changes: 7 additions & 7 deletions rpcs3/Emu/CPU/CPUThread.h
Expand Up @@ -8,7 +8,7 @@ enum class cpu_flag : u32
{
stop, // Thread not running (HLE, initial state)
exit, // Irreversible exit
suspend, // Thread paused
suspend, // Thread suspended
ret, // Callback return requested
signal, // Thread received a signal (HLE)

Expand Down Expand Up @@ -38,29 +38,29 @@ class cpu_thread : public named_thread
// Public thread state
atomic_t<bs_t<cpu_flag>> state{+cpu_flag::stop};

// Object associated with sleep state, possibly synchronization primitive (mutex, semaphore, etc.)
atomic_t<void*> owner{};

// Process thread state, return true if the checker must return
bool check_state();

// Run thread
void run();

// Set cpu_flag::signal
void set_signal();

// Check thread type
u32 id_type()
{
return id >> 24;
}

// Thread stats for external observation
static atomic_t<u64> g_threads_created, g_threads_deleted;

// Print CPU state
virtual std::string dump() const;

// Thread entry point function
virtual void cpu_task() = 0;

// Callback for cpu_flag::suspend
virtual void cpu_sleep() {}
};

inline cpu_thread* get_current_cpu_thread() noexcept
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/Emu/Cell/Modules/cellAdec.cpp
Expand Up @@ -2,6 +2,7 @@
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_sync.h"

extern "C"
{
Expand Down Expand Up @@ -199,6 +200,7 @@ class AudioDecoder : public ppu_thread
// TODO: finalize
cellAdec.warning("adecEndSeq:");
cbFunc(*this, id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, cbArg);
lv2_obj::sleep(*this, -1);

just_finished = true;
break;
Expand Down Expand Up @@ -375,11 +377,13 @@ class AudioDecoder : public ppu_thread
{
frame.data = nullptr; // to prevent destruction
cbFunc(*this, id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, cbArg);
lv2_obj::sleep(*this, -1);
}
}
}

cbFunc(*this, id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, cbArg);
lv2_obj::sleep(*this, -1);
break;
}

Expand Down
7 changes: 7 additions & 0 deletions rpcs3/Emu/Cell/Modules/cellDmux.cpp
Expand Up @@ -2,6 +2,7 @@
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_sync.h"

#include "cellPamf.h"
#include "cellDmux.h"
Expand Down Expand Up @@ -242,6 +243,7 @@ class Demuxer : public ppu_thread
dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE;
dmuxMsg->supplementalInfo = stream.userdata;
cbFunc(*this, id, dmuxMsg, cbArg);
lv2_obj::sleep(*this, -1);

is_working = false;

Expand Down Expand Up @@ -395,6 +397,7 @@ class Demuxer : public ppu_thread
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this, -1);
}
}
else
Expand Down Expand Up @@ -460,6 +463,7 @@ class Demuxer : public ppu_thread
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this, -1);
}

if (pes.has_ts)
Expand Down Expand Up @@ -536,6 +540,7 @@ class Demuxer : public ppu_thread
dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE;
dmuxMsg->supplementalInfo = stream.userdata;
cbFunc(*this, id, dmuxMsg, cbArg);
lv2_obj::sleep(*this, -1);

stream = {};

Expand Down Expand Up @@ -624,6 +629,7 @@ class Demuxer : public ppu_thread
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this, -1);
}

if (es.raw_data.size())
Expand All @@ -636,6 +642,7 @@ class Demuxer : public ppu_thread
esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_FLUSH_DONE;
esMsg->supplementalInfo = stream.userdata;
es.cbFunc(*this, id, es.id, esMsg, es.cbArg);
lv2_obj::sleep(*this, -1);
break;
}

Expand Down

0 comments on commit 77e1885

Please sign in to comment.