summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.h
diff options
context:
space:
mode:
authorGravatar bunnei2018-01-01 14:02:26 -0500
committerGravatar bunnei2018-01-01 14:02:26 -0500
commitb9950cd4b0cf414ca97daa5f7578f4ca22b2669d (patch)
tree194c711f7f02e68e5137f3f7287dbd21ab834d5b /src/core/hle/kernel/mutex.h
parentkernel: Add ObjectAddressTable class. (diff)
downloadyuzu-b9950cd4b0cf414ca97daa5f7578f4ca22b2669d.tar.gz
yuzu-b9950cd4b0cf414ca97daa5f7578f4ca22b2669d.tar.xz
yuzu-b9950cd4b0cf414ca97daa5f7578f4ca22b2669d.zip
svc: Implement svcLockMutex.
Diffstat (limited to 'src/core/hle/kernel/mutex.h')
-rw-r--r--src/core/hle/kernel/mutex.h37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h
index 503d3ee75..87e3c15ee 100644
--- a/src/core/hle/kernel/mutex.h
+++ b/src/core/hle/kernel/mutex.h
@@ -6,8 +6,10 @@
6 6
7#include <string> 7#include <string>
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "common/swap.h"
9#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
10#include "core/hle/kernel/wait_object.h" 11#include "core/hle/kernel/wait_object.h"
12#include "core/hle/result.h"
11 13
12namespace Kernel { 14namespace Kernel {
13 15
@@ -17,11 +19,15 @@ class Mutex final : public WaitObject {
17public: 19public:
18 /** 20 /**
19 * Creates a mutex. 21 * Creates a mutex.
20 * @param initial_locked Specifies if the mutex should be locked initially 22 * @param holding_thread Specifies a thread already holding the mutex. If not nullptr, this
23 * thread will acquire the mutex.
24 * @param guest_addr Address of the object tracking the mutex in guest memory. If specified,
25 * this mutex will update the guest object when its state changes.
21 * @param name Optional name of mutex 26 * @param name Optional name of mutex
22 * @return Pointer to new Mutex object 27 * @return Pointer to new Mutex object
23 */ 28 */
24 static SharedPtr<Mutex> Create(bool initial_locked, VAddr addr, std::string name = "Unknown"); 29 static SharedPtr<Mutex> Create(SharedPtr<Kernel::Thread> holding_thread, VAddr guest_addr = 0,
30 std::string name = "Unknown");
25 31
26 std::string GetTypeName() const override { 32 std::string GetTypeName() const override {
27 return "Mutex"; 33 return "Mutex";
@@ -39,7 +45,7 @@ public:
39 u32 priority; ///< The priority of the mutex, used for priority inheritance. 45 u32 priority; ///< The priority of the mutex, used for priority inheritance.
40 std::string name; ///< Name of mutex (optional) 46 std::string name; ///< Name of mutex (optional)
41 SharedPtr<Thread> holding_thread; ///< Thread that has acquired the mutex 47 SharedPtr<Thread> holding_thread; ///< Thread that has acquired the mutex
42 VAddr addr; 48 VAddr guest_addr; ///< Address of the guest mutex value
43 49
44 /** 50 /**
45 * Elevate the mutex priority to the best priority 51 * Elevate the mutex priority to the best priority
@@ -53,11 +59,32 @@ public:
53 void AddWaitingThread(SharedPtr<Thread> thread) override; 59 void AddWaitingThread(SharedPtr<Thread> thread) override;
54 void RemoveWaitingThread(Thread* thread) override; 60 void RemoveWaitingThread(Thread* thread) override;
55 61
56 void Release(); 62 /**
63 * Attempts to release the mutex from the specified thread.
64 * @param thread Thread that wants to release the mutex.
65 * @returns The result code of the operation.
66 */
67 ResultCode Release(Thread* thread);
57 68
58private: 69private:
59 Mutex(); 70 Mutex();
60 ~Mutex() override; 71 ~Mutex() override;
72
73 /// Object in guest memory used to track the mutex state
74 union GuestState {
75 u32_le raw;
76 /// Handle of the thread that currently holds the mutex, 0 if available
77 BitField<0, 30, u32_le> holding_thread_handle;
78 /// 1 when there are threads waiting for this mutex, otherwise 0
79 BitField<30, 1, u32_le> has_waiters;
80 };
81 static_assert(sizeof(GuestState) == 4, "GuestState size is incorrect");
82
83 /// Updates the state of the object tracking this mutex in guest memory
84 void UpdateGuestState();
85
86 /// Verifies the state of the object tracking this mutex in guest memory
87 void VerifyGuestState();
61}; 88};
62 89
63/** 90/**
@@ -66,4 +93,4 @@ private:
66 */ 93 */
67void ReleaseThreadMutexes(Thread* thread); 94void ReleaseThreadMutexes(Thread* thread);
68 95
69} // namespace 96} // namespace Kernel