citra-emu
/
citra-canary
Archived
1
0
Fork 0

Kernel: pass ref in Mutex

This commit is contained in:
Weiyi Wang 2018-10-11 16:00:09 -04:00
parent eec11a94cb
commit 7449ba85a6
9 changed files with 27 additions and 22 deletions

View File

@ -12,6 +12,7 @@ namespace Kernel {
class AddressArbiter;
class Event;
class Mutex;
enum class ResetType {
OneShot,
@ -41,6 +42,14 @@ public:
* @param name Optional name of event
*/
SharedPtr<Event> CreateEvent(ResetType reset_type, std::string name = "Unknown");
/**
* Creates a mutex.
* @param initial_locked Specifies if the mutex should be locked initially
* @param name Optional name of mutex
* @return Pointer to new Mutex object
*/
SharedPtr<Mutex> CreateMutex(bool initial_locked, std::string name = "Unknown");
};
} // namespace Kernel

View File

@ -24,11 +24,11 @@ void ReleaseThreadMutexes(Thread* thread) {
thread->held_mutexes.clear();
}
Mutex::Mutex() {}
Mutex::Mutex(KernelSystem& kernel) {}
Mutex::~Mutex() {}
SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) {
SharedPtr<Mutex> mutex(new Mutex);
SharedPtr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {
SharedPtr<Mutex> mutex(new Mutex(*this));
mutex->lock_count = 0;
mutex->name = std::move(name);

View File

@ -16,14 +16,6 @@ class Thread;
class Mutex final : public WaitObject {
public:
/**
* Creates a mutex.
* @param initial_locked Specifies if the mutex should be locked initially
* @param name Optional name of mutex
* @return Pointer to new Mutex object
*/
static SharedPtr<Mutex> Create(bool initial_locked, std::string name = "Unknown");
std::string GetTypeName() const override {
return "Mutex";
}
@ -61,8 +53,10 @@ public:
ResultCode Release(Thread* thread);
private:
Mutex();
explicit Mutex(KernelSystem& kernel);
~Mutex() override;
friend class KernelSystem;
};
/**

View File

@ -828,7 +828,7 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) {
/// Create a mutex
static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) {
SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0);
SharedPtr<Mutex> mutex = Core::System::GetInstance().Kernel().CreateMutex(initial_locked != 0);
mutex->name = fmt::format("mutex-{:08x}", Core::CPU().GetReg(14));
CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(mutex)));

View File

@ -1455,16 +1455,16 @@ void Module::Interface::GetMetaDataFromCia(Kernel::HLERequestContext& ctx) {
rb.PushMappedBuffer(output_buffer);
}
Module::Module() {
Module::Module(Core::System& system) {
ScanForAllTitles();
system_updater_mutex = Kernel::Mutex::Create(false, "AM::SystemUpdaterMutex");
system_updater_mutex = system.Kernel().CreateMutex(false, "AM::SystemUpdaterMutex");
}
Module::~Module() = default;
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
auto am = std::make_shared<Module>();
auto am = std::make_shared<Module>(system);
std::make_shared<AM_APP>(am)->InstallAsService(service_manager);
std::make_shared<AM_NET>(am)->InstallAsService(service_manager);
std::make_shared<AM_SYS>(am)->InstallAsService(service_manager);

View File

@ -149,7 +149,7 @@ std::string GetMediaTitlePath(Service::FS::MediaType media_type);
class Module final {
public:
Module();
explicit Module(Core::System& system);
~Module();
class Interface : public ServiceFramework<Interface> {

View File

@ -859,7 +859,7 @@ Module::Module(Core::System& system) : system(system) {
MemoryPermission::ReadWrite, MemoryPermission::Read, 0,
Kernel::MemoryRegion::SYSTEM, "APT:SharedFont");
lock = Kernel::Mutex::Create(false, "APT_U:Lock");
lock = system.Kernel().CreateMutex(false, "APT_U:Lock");
}
Module::~Module() {}

View File

@ -19,7 +19,7 @@ void CSND_SND::Initialize(Kernel::HLERequestContext& ctx) {
const u32 offset3 = rp.Pop<u32>();
using Kernel::MemoryPermission;
mutex = Kernel::Mutex::Create(false, "CSND:mutex");
mutex = system.Kernel().CreateMutex(false, "CSND:mutex");
shared_memory = Kernel::SharedMemory::Create(nullptr, size, MemoryPermission::ReadWrite,
MemoryPermission::ReadWrite, 0,
Kernel::MemoryRegion::BASE, "CSND:SharedMemory");
@ -173,7 +173,7 @@ void CSND_SND::Reset(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_CSND, "(STUBBED) called");
}
CSND_SND::CSND_SND() : ServiceFramework("csnd:SND", 4) {
CSND_SND::CSND_SND(Core::System& system) : ServiceFramework("csnd:SND", 4), system(system) {
static const FunctionInfo functions[] = {
// clang-format off
{0x00010140, &CSND_SND::Initialize, "Initialize"},
@ -196,7 +196,7 @@ CSND_SND::CSND_SND() : ServiceFramework("csnd:SND", 4) {
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
std::make_shared<CSND_SND>()->InstallAsService(service_manager);
std::make_shared<CSND_SND>(system)->InstallAsService(service_manager);
}
} // namespace Service::CSND

View File

@ -16,7 +16,7 @@ namespace Service::CSND {
class CSND_SND final : public ServiceFramework<CSND_SND> {
public:
CSND_SND();
explicit CSND_SND(Core::System& system);
~CSND_SND() = default;
private:
@ -174,6 +174,8 @@ private:
};
static_assert(sizeof(Type0Command) == 0x20, "Type0Command structure size is wrong");
Core::System& system;
Kernel::SharedPtr<Kernel::Mutex> mutex = nullptr;
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr;