summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/mutex.h')
-rw-r--r--src/core/hle/kernel/mutex.h88
1 files changed, 12 insertions, 76 deletions
diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h
index 38db21005..3117e7c70 100644
--- a/src/core/hle/kernel/mutex.h
+++ b/src/core/hle/kernel/mutex.h
@@ -15,87 +15,23 @@ namespace Kernel {
15 15
16class Thread; 16class Thread;
17 17
18class Mutex final : public WaitObject { 18class Mutex final {
19public: 19public:
20 /** 20 /// Flag that indicates that a mutex still has threads waiting for it.
21 * Creates a mutex. 21 static constexpr u32 MutexHasWaitersFlag = 0x40000000;
22 * @param holding_thread Specifies a thread already holding the mutex. If not nullptr, this 22 /// Mask of the bits in a mutex address value that contain the mutex owner.
23 * thread will acquire the mutex. 23 static constexpr u32 MutexOwnerMask = 0xBFFFFFFF;
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.
26 * @param name Optional name of mutex
27 * @return Pointer to new Mutex object
28 */
29 static SharedPtr<Mutex> Create(SharedPtr<Kernel::Thread> holding_thread, VAddr guest_addr = 0,
30 std::string name = "Unknown");
31 24
32 std::string GetTypeName() const override { 25 /// Attempts to acquire a mutex at the specified address.
33 return "Mutex"; 26 static ResultCode TryAcquire(VAddr address, Handle holding_thread_handle,
34 } 27 Handle requesting_thread_handle);
35 std::string GetName() const override {
36 return name;
37 }
38 28
39 static const HandleType HANDLE_TYPE = HandleType::Mutex; 29 /// Releases the mutex at the specified address.
40 HandleType GetHandleType() const override { 30 static ResultCode Release(VAddr address);
41 return HANDLE_TYPE;
42 }
43
44 u32 priority; ///< The priority of the mutex, used for priority inheritance.
45 std::string name; ///< Name of mutex (optional)
46 VAddr guest_addr; ///< Address of the guest mutex value
47
48 /**
49 * Elevate the mutex priority to the best priority
50 * among the priorities of all its waiting threads.
51 */
52 void UpdatePriority();
53
54 bool ShouldWait(Thread* thread) const override;
55 void Acquire(Thread* thread) override;
56
57 void AddWaitingThread(SharedPtr<Thread> thread) override;
58 void RemoveWaitingThread(Thread* thread) override;
59
60 /**
61 * Attempts to release the mutex from the specified thread.
62 * @param thread Thread that wants to release the mutex.
63 * @returns The result code of the operation.
64 */
65 ResultCode Release(Thread* thread);
66
67 /// Gets the handle to the holding process stored in the guest state.
68 Handle GetOwnerHandle() const;
69
70 /// Gets the Thread pointed to by the owner handle
71 SharedPtr<Thread> GetHoldingThread() const;
72 /// Sets the holding process handle in the guest state.
73 void SetHoldingThread(SharedPtr<Thread> thread);
74
75 /// Returns the has_waiters bit in the guest state.
76 bool GetHasWaiters() const;
77 /// Sets the has_waiters bit in the guest state.
78 void SetHasWaiters(bool has_waiters);
79 31
80private: 32private:
81 Mutex(); 33 Mutex() = default;
82 ~Mutex() override; 34 ~Mutex() = default;
83
84 /// Object in guest memory used to track the mutex state
85 union GuestState {
86 u32_le raw;
87 /// Handle of the thread that currently holds the mutex, 0 if available
88 BitField<0, 30, u32_le> holding_thread_handle;
89 /// 1 when there are threads waiting for this mutex, otherwise 0
90 BitField<30, 1, u32_le> has_waiters;
91 };
92 static_assert(sizeof(GuestState) == 4, "GuestState size is incorrect");
93}; 35};
94 36
95/**
96 * Releases all the mutexes held by the specified thread
97 * @param thread Thread that is holding the mutexes
98 */
99void ReleaseThreadMutexes(Thread* thread);
100
101} // namespace Kernel 37} // namespace Kernel