Kernel: pass ref in Mutex
This commit is contained in:
parent
eec11a94cb
commit
7449ba85a6
9 changed files with 27 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue