diff options
author | bunnei <bunneidev@gmail.com> | 2015-01-18 04:23:49 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2015-01-22 01:10:24 +0100 |
commit | aa01c57ae9d73e41b65d37860ca6fbb91caba33a (patch) | |
tree | 904936860b1e8319ec5edc3a1e0e6c2c12f01d9f /src/core/hle | |
parent | WaitSynchronizationN: Handle case where handles=nullptr. (diff) | |
download | yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.gz yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.bz2 yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.lz yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.xz yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.zst yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.zip |
Diffstat (limited to 'src/core/hle')
-rw-r--r-- | src/core/hle/kernel/event.cpp | 6 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.h | 13 | ||||
-rw-r--r-- | src/core/hle/kernel/mutex.cpp | 19 | ||||
-rw-r--r-- | src/core/hle/kernel/semaphore.cpp | 15 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.cpp | 6 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.h | 3 | ||||
-rw-r--r-- | src/core/hle/kernel/timer.cpp | 6 | ||||
-rw-r--r-- | src/core/hle/svc.cpp | 9 |
8 files changed, 59 insertions, 18 deletions
diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index 4173a980b..41e1bd6c5 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -28,7 +28,7 @@ public: bool signaled; ///< Whether the event has already been signaled std::string name; ///< Name of event (optional) - ResultVal<bool> WaitSynchronization(unsigned index) override { + ResultVal<bool> Wait(unsigned index) override { bool wait = !signaled; if (wait) { AddWaitingThread(GetCurrentThread()); @@ -36,6 +36,10 @@ public: } return MakeResult<bool>(wait); } + + ResultVal<bool> Acquire() override { + return MakeResult<bool>(true); + } }; ResultCode SignalEvent(const Handle handle) { diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index af4e2f443..d98fd0389 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -65,11 +65,20 @@ public: virtual Kernel::HandleType GetHandleType() const = 0; /** - * Wait for kernel object to synchronize. + * Wait the current thread for kernel object to synchronize. * @param index Index of wait object (only applies to WaitSynchronizationN) * @return True if the current thread should wait as a result of the wait */ - virtual ResultVal<bool> WaitSynchronization(unsigned index=0) { + virtual ResultVal<bool> Wait(unsigned index = 0) { + LOG_ERROR(Kernel, "(UNIMPLEMENTED)"); + return UnimplementedFunction(ErrorModule::Kernel); + } + + /** + * Acquire/lock the kernel object if it is available + * @return True if we were able to acquire the kernel object, otherwise false + */ + virtual ResultVal<bool> Acquire() { LOG_ERROR(Kernel, "(UNIMPLEMENTED)"); return UnimplementedFunction(ErrorModule::Kernel); } diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 78063b8f1..37e7be4e7 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -26,7 +26,8 @@ public: Handle lock_thread; ///< Handle to thread that currently has mutex std::string name; ///< Name of mutex (optional) - ResultVal<bool> WaitSynchronization(unsigned index) override; + ResultVal<bool> Wait(unsigned index) override; + ResultVal<bool> Acquire() override; }; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -155,17 +156,25 @@ Handle CreateMutex(bool initial_locked, const std::string& name) { return handle; } -ResultVal<bool> Mutex::WaitSynchronization(unsigned index) { - bool wait = locked; +ResultVal<bool> Mutex::Wait(unsigned index) { if (locked) { AddWaitingThread(GetCurrentThread()); Kernel::WaitCurrentThread_WaitSynchronization(WAITTYPE_MUTEX, this, index); - } else { + } + + return MakeResult<bool>(locked); +} + +ResultVal<bool> Mutex::Acquire() { + bool res = false; + + if (!locked) { // Lock the mutex when the first thread accesses it locked = true; + res = true; MutexAcquireLock(this); } - return MakeResult<bool>(wait); + return MakeResult<bool>(res); } } // namespace diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp index 288928441..6464b2580 100644 --- a/src/core/hle/kernel/semaphore.cpp +++ b/src/core/hle/kernel/semaphore.cpp @@ -32,18 +32,27 @@ public: return available_count > 0; } - ResultVal<bool> WaitSynchronization(unsigned index) override { + ResultVal<bool> Wait(unsigned index) override { bool wait = !IsAvailable(); if (wait) { Kernel::WaitCurrentThread_WaitSynchronization(WAITTYPE_SEMA, this, index); AddWaitingThread(GetCurrentThread()); - } else { - --available_count; } return MakeResult<bool>(wait); } + + ResultVal<bool> Acquire() override { + bool res = false; + + if (IsAvailable()) { + --available_count; + res = true; + } + + return MakeResult<bool>(res); + } }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 0c9ecc091..6b0bdebb5 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -22,7 +22,7 @@ namespace Kernel { -ResultVal<bool> Thread::WaitSynchronization(unsigned index) { +ResultVal<bool> Thread::Wait(unsigned index) { const bool wait = status != THREADSTATUS_DORMANT; if (wait) { AddWaitingThread(GetCurrentThread()); @@ -32,6 +32,10 @@ ResultVal<bool> Thread::WaitSynchronization(unsigned index) { return MakeResult<bool>(wait); } +ResultVal<bool> Thread::Acquire() { + return MakeResult<bool>(true); +} + // Lists all thread ids that aren't deleted/etc. static std::vector<SharedPtr<Thread>> thread_list; diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index f3dc4eec0..9faf89c15 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -70,7 +70,8 @@ public: inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; } inline bool IsIdle() const { return idle; } - ResultVal<bool> WaitSynchronization(unsigned index) override; + ResultVal<bool> Wait(unsigned index) override; + ResultVal<bool> Acquire() override; s32 GetPriority() const { return current_priority; } void SetPriority(s32 priority); diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index c97ae6c5c..6497bb349 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -29,7 +29,7 @@ public: u64 initial_delay; ///< The delay until the timer fires for the first time u64 interval_delay; ///< The delay until the timer fires after the first time - ResultVal<bool> WaitSynchronization(unsigned index) override { + ResultVal<bool> Wait(unsigned index) override { bool wait = !signaled; if (wait) { AddWaitingThread(GetCurrentThread()); @@ -37,6 +37,10 @@ public: } return MakeResult<bool>(wait); } + + ResultVal<bool> Acquire() override { + return MakeResult<bool>(true); + } }; /** diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 23885f129..a27aa6269 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -127,7 +127,7 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) { LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds); - ResultVal<bool> wait = object->WaitSynchronization(); + ResultVal<bool> wait = object->Wait(); // Check for next thread to schedule if (wait.Succeeded() && *wait) { @@ -137,6 +137,8 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) { Kernel::GetCurrentThread()->SetWaitAll(false); HLE::Reschedule(__func__); + } else { + object->Acquire(); } return wait.Code().raw; @@ -163,15 +165,14 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, if (object == nullptr) return InvalidHandle(ErrorModule::Kernel).raw; - ResultVal<bool> wait = object->WaitSynchronization(handle_index); + ResultVal<bool> wait = object->Wait(handle_index); wait_thread = (wait.Succeeded() && *wait); // If this object waited and we are waiting on all objects to synchronize - if (wait_thread && wait_all) { + if (wait_thread && wait_all) // Enforce later on that this thread does not continue wait_all_succeeded = true; - } // If this object synchronized and we are not waiting on all objects to synchronize if (!wait_thread && !wait_all) |