diff options
| author | 2018-04-20 14:42:29 -0500 | |
|---|---|---|
| committer | 2018-04-20 21:04:32 -0500 | |
| commit | 5fdfbfe25adafd2734a19fe94cccc58993cb12e7 (patch) | |
| tree | a4940a8231d08c5b96ce2d629acc04948ab1af3a /src/core/hle/kernel/mutex.cpp | |
| parent | Kernel: Properly implemented svcWaitProcessWideKey and svcSignalProcessWideKey (diff) | |
| download | yuzu-5fdfbfe25adafd2734a19fe94cccc58993cb12e7.tar.gz yuzu-5fdfbfe25adafd2734a19fe94cccc58993cb12e7.tar.xz yuzu-5fdfbfe25adafd2734a19fe94cccc58993cb12e7.zip | |
Kernel: Remove old and unused Mutex code.
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 50a9a0805..5cc0bd266 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -40,126 +40,6 @@ static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread(VA | |||
| 40 | return {highest_priority_thread, num_waiters}; | 40 | return {highest_priority_thread, num_waiters}; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | void ReleaseThreadMutexes(Thread* thread) { | ||
| 44 | for (auto& mtx : thread->held_mutexes) { | ||
| 45 | mtx->SetHasWaiters(false); | ||
| 46 | mtx->SetHoldingThread(nullptr); | ||
| 47 | mtx->WakeupAllWaitingThreads(); | ||
| 48 | } | ||
| 49 | thread->held_mutexes.clear(); | ||
| 50 | } | ||
| 51 | |||
| 52 | Mutex::Mutex() {} | ||
| 53 | Mutex::~Mutex() {} | ||
| 54 | |||
| 55 | SharedPtr<Mutex> Mutex::Create(SharedPtr<Kernel::Thread> holding_thread, VAddr guest_addr, | ||
| 56 | std::string name) { | ||
| 57 | SharedPtr<Mutex> mutex(new Mutex); | ||
| 58 | |||
| 59 | mutex->guest_addr = guest_addr; | ||
| 60 | mutex->name = std::move(name); | ||
| 61 | |||
| 62 | // If mutex was initialized with a holding thread, acquire it by the holding thread | ||
| 63 | if (holding_thread) { | ||
| 64 | mutex->Acquire(holding_thread.get()); | ||
| 65 | } | ||
| 66 | |||
| 67 | // Mutexes are referenced by guest address, so track this in the kernel | ||
| 68 | g_object_address_table.Insert(guest_addr, mutex); | ||
| 69 | |||
| 70 | return mutex; | ||
| 71 | } | ||
| 72 | |||
| 73 | bool Mutex::ShouldWait(Thread* thread) const { | ||
| 74 | auto holding_thread = GetHoldingThread(); | ||
| 75 | return holding_thread != nullptr && thread != holding_thread; | ||
| 76 | } | ||
| 77 | |||
| 78 | void Mutex::Acquire(Thread* thread) { | ||
| 79 | ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); | ||
| 80 | |||
| 81 | priority = thread->current_priority; | ||
| 82 | thread->held_mutexes.insert(this); | ||
| 83 | SetHoldingThread(thread); | ||
| 84 | thread->UpdatePriority(); | ||
| 85 | Core::System::GetInstance().PrepareReschedule(); | ||
| 86 | } | ||
| 87 | |||
| 88 | ResultCode Mutex::Release(Thread* thread) { | ||
| 89 | auto holding_thread = GetHoldingThread(); | ||
| 90 | ASSERT(holding_thread); | ||
| 91 | |||
| 92 | // We can only release the mutex if it's held by the calling thread. | ||
| 93 | ASSERT(thread == holding_thread); | ||
| 94 | |||
| 95 | holding_thread->held_mutexes.erase(this); | ||
| 96 | holding_thread->UpdatePriority(); | ||
| 97 | SetHoldingThread(nullptr); | ||
| 98 | SetHasWaiters(!GetWaitingThreads().empty()); | ||
| 99 | WakeupAllWaitingThreads(); | ||
| 100 | Core::System::GetInstance().PrepareReschedule(); | ||
| 101 | |||
| 102 | return RESULT_SUCCESS; | ||
| 103 | } | ||
| 104 | |||
| 105 | void Mutex::AddWaitingThread(SharedPtr<Thread> thread) { | ||
| 106 | WaitObject::AddWaitingThread(thread); | ||
| 107 | thread->pending_mutexes.insert(this); | ||
| 108 | SetHasWaiters(true); | ||
| 109 | UpdatePriority(); | ||
| 110 | } | ||
| 111 | |||
| 112 | void Mutex::RemoveWaitingThread(Thread* thread) { | ||
| 113 | WaitObject::RemoveWaitingThread(thread); | ||
| 114 | thread->pending_mutexes.erase(this); | ||
| 115 | if (!GetHasWaiters()) | ||
| 116 | SetHasWaiters(!GetWaitingThreads().empty()); | ||
| 117 | UpdatePriority(); | ||
| 118 | } | ||
| 119 | |||
| 120 | void Mutex::UpdatePriority() { | ||
| 121 | if (!GetHoldingThread()) | ||
| 122 | return; | ||
| 123 | |||
| 124 | u32 best_priority = THREADPRIO_LOWEST; | ||
| 125 | for (auto& waiter : GetWaitingThreads()) { | ||
| 126 | if (waiter->current_priority < best_priority) | ||
| 127 | best_priority = waiter->current_priority; | ||
| 128 | } | ||
| 129 | |||
| 130 | if (best_priority != priority) { | ||
| 131 | priority = best_priority; | ||
| 132 | GetHoldingThread()->UpdatePriority(); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | Handle Mutex::GetOwnerHandle() const { | ||
| 137 | GuestState guest_state{Memory::Read32(guest_addr)}; | ||
| 138 | return guest_state.holding_thread_handle; | ||
| 139 | } | ||
| 140 | |||
| 141 | SharedPtr<Thread> Mutex::GetHoldingThread() const { | ||
| 142 | GuestState guest_state{Memory::Read32(guest_addr)}; | ||
| 143 | return g_handle_table.Get<Thread>(guest_state.holding_thread_handle); | ||
| 144 | } | ||
| 145 | |||
| 146 | void Mutex::SetHoldingThread(SharedPtr<Thread> thread) { | ||
| 147 | GuestState guest_state{Memory::Read32(guest_addr)}; | ||
| 148 | guest_state.holding_thread_handle.Assign(thread ? thread->guest_handle : 0); | ||
| 149 | Memory::Write32(guest_addr, guest_state.raw); | ||
| 150 | } | ||
| 151 | |||
| 152 | bool Mutex::GetHasWaiters() const { | ||
| 153 | GuestState guest_state{Memory::Read32(guest_addr)}; | ||
| 154 | return guest_state.has_waiters != 0; | ||
| 155 | } | ||
| 156 | |||
| 157 | void Mutex::SetHasWaiters(bool has_waiters) { | ||
| 158 | GuestState guest_state{Memory::Read32(guest_addr)}; | ||
| 159 | guest_state.has_waiters.Assign(has_waiters ? 1 : 0); | ||
| 160 | Memory::Write32(guest_addr, guest_state.raw); | ||
| 161 | } | ||
| 162 | |||
| 163 | ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle, | 43 | ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle, |
| 164 | Handle requesting_thread_handle) { | 44 | Handle requesting_thread_handle) { |
| 165 | // The mutex address must be 4-byte aligned | 45 | // The mutex address must be 4-byte aligned |