mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-04 22:37:53 +00:00
Kernel: Changed "ShouldWait" to return bool and "Acquire" to return void.
This commit is contained in:
parent
c68eb15695
commit
15b6a4d9ad
9 changed files with 42 additions and 71 deletions
|
@ -28,16 +28,16 @@ public:
|
||||||
bool signaled; ///< Whether the event has already been signaled
|
bool signaled; ///< Whether the event has already been signaled
|
||||||
std::string name; ///< Name of event (optional)
|
std::string name; ///< Name of event (optional)
|
||||||
|
|
||||||
ResultVal<bool> ShouldWait() override {
|
bool ShouldWait() override {
|
||||||
return MakeResult<bool>(!signaled);
|
return !signaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> Acquire() override {
|
void Acquire() override {
|
||||||
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
||||||
|
|
||||||
// Release the event if it's not sticky...
|
// Release the event if it's not sticky...
|
||||||
if (reset_type != RESETTYPE_STICKY)
|
if (reset_type != RESETTYPE_STICKY)
|
||||||
signaled = false;
|
signaled = false;
|
||||||
|
|
||||||
return MakeResult<bool>(true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -120,13 +120,10 @@ public:
|
||||||
* Check if the current thread should wait until the object is available
|
* Check if the current thread should wait until the object is available
|
||||||
* @return True if the current thread should wait due to this object being unavailable
|
* @return True if the current thread should wait due to this object being unavailable
|
||||||
*/
|
*/
|
||||||
virtual ResultVal<bool> ShouldWait() = 0;
|
virtual bool ShouldWait() = 0;
|
||||||
|
|
||||||
/**
|
/// Acquire/lock the object if it is available
|
||||||
* Acquire/lock the object if it is available
|
virtual void Acquire() = 0;
|
||||||
* @return True if we were able to acquire this object, otherwise false
|
|
||||||
*/
|
|
||||||
virtual ResultVal<bool> Acquire() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a thread to wait on this object
|
* Add a thread to wait on this object
|
||||||
|
|
|
@ -27,8 +27,8 @@ public:
|
||||||
std::string name; ///< Name of mutex (optional)
|
std::string name; ///< Name of mutex (optional)
|
||||||
SharedPtr<Thread> current_thread; ///< Thread that has acquired the mutex
|
SharedPtr<Thread> current_thread; ///< Thread that has acquired the mutex
|
||||||
|
|
||||||
ResultVal<bool> ShouldWait() override;
|
bool ShouldWait() override;
|
||||||
ResultVal<bool> Acquire() override;
|
void Acquire() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -159,20 +159,14 @@ Handle CreateMutex(bool initial_locked, const std::string& name) {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> Mutex::ShouldWait() {
|
bool Mutex::ShouldWait() {
|
||||||
return MakeResult<bool>(locked && (current_thread != GetCurrentThread()));
|
return locked && current_thread != GetCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> Mutex::Acquire() {
|
void Mutex::Acquire() {
|
||||||
bool res = false;
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
||||||
|
|
||||||
if (!locked) {
|
|
||||||
// Lock the mutex when the first thread accesses it
|
|
||||||
locked = true;
|
locked = true;
|
||||||
res = true;
|
|
||||||
MutexAcquireLock(this);
|
MutexAcquireLock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return MakeResult<bool>(res);
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -24,27 +24,13 @@ public:
|
||||||
s32 available_count; ///< Number of free slots left in the semaphore
|
s32 available_count; ///< Number of free slots left in the semaphore
|
||||||
std::string name; ///< Name of semaphore (optional)
|
std::string name; ///< Name of semaphore (optional)
|
||||||
|
|
||||||
/**
|
bool ShouldWait() override {
|
||||||
* Tests whether a semaphore still has free slots
|
return available_count <= 0;
|
||||||
* @return Whether the semaphore is available
|
|
||||||
*/
|
|
||||||
bool IsAvailable() const {
|
|
||||||
return available_count > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> ShouldWait() override {
|
void Acquire() override {
|
||||||
return MakeResult<bool>(!IsAvailable());
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
||||||
}
|
|
||||||
|
|
||||||
ResultVal<bool> Acquire() override {
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
if (IsAvailable()) {
|
|
||||||
--available_count;
|
--available_count;
|
||||||
res = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MakeResult<bool>(res);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,8 +70,8 @@ ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) {
|
||||||
|
|
||||||
// Notify some of the threads that the semaphore has been released
|
// Notify some of the threads that the semaphore has been released
|
||||||
// stop once the semaphore is full again or there are no more waiting threads
|
// stop once the semaphore is full again or there are no more waiting threads
|
||||||
while (semaphore->IsAvailable() && semaphore->ReleaseNextThread() != nullptr) {
|
while (!semaphore->ShouldWait() && semaphore->ReleaseNextThread() != nullptr) {
|
||||||
--semaphore->available_count;
|
semaphore->Acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
|
@ -57,12 +57,12 @@ public:
|
||||||
// TODO(bunnei): These functions exist to satisfy a hardware test with a Session object
|
// TODO(bunnei): These functions exist to satisfy a hardware test with a Session object
|
||||||
// passed into WaitSynchronization. Figure out the meaning of them.
|
// passed into WaitSynchronization. Figure out the meaning of them.
|
||||||
|
|
||||||
ResultVal<bool> ShouldWait() override {
|
bool ShouldWait() override {
|
||||||
return MakeResult<bool>(true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> Acquire() override {
|
void Acquire() override {
|
||||||
return MakeResult<bool>(false);
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ResultVal<bool> Thread::ShouldWait() {
|
bool Thread::ShouldWait() {
|
||||||
return MakeResult<bool>(status != THREADSTATUS_DORMANT);
|
return status != THREADSTATUS_DORMANT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> Thread::Acquire() {
|
void Thread::Acquire() {
|
||||||
return MakeResult<bool>(true);
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lists all thread ids that aren't deleted/etc.
|
// Lists all thread ids that aren't deleted/etc.
|
||||||
|
@ -269,9 +269,7 @@ void Thread::ReleaseWaitObject(WaitObject* wait_object) {
|
||||||
|
|
||||||
// Iterate through all waiting objects to check availability...
|
// Iterate through all waiting objects to check availability...
|
||||||
for (auto itr = wait_objects.begin(); itr != wait_objects.end(); ++itr) {
|
for (auto itr = wait_objects.begin(); itr != wait_objects.end(); ++itr) {
|
||||||
auto res = (*itr)->ShouldWait();
|
if ((*itr)->ShouldWait())
|
||||||
|
|
||||||
if (*res && res.Succeeded())
|
|
||||||
wait_all_failed = true;
|
wait_all_failed = true;
|
||||||
|
|
||||||
// The output should be the last index of wait_object
|
// The output should be the last index of wait_object
|
||||||
|
|
|
@ -58,8 +58,8 @@ public:
|
||||||
inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; }
|
inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; }
|
||||||
inline bool IsIdle() const { return idle; }
|
inline bool IsIdle() const { return idle; }
|
||||||
|
|
||||||
ResultVal<bool> ShouldWait() override;
|
bool ShouldWait() override;
|
||||||
ResultVal<bool> Acquire() override;
|
void Acquire() override;
|
||||||
|
|
||||||
s32 GetPriority() const { return current_priority; }
|
s32 GetPriority() const { return current_priority; }
|
||||||
void SetPriority(s32 priority);
|
void SetPriority(s32 priority);
|
||||||
|
|
|
@ -29,12 +29,12 @@ public:
|
||||||
u64 initial_delay; ///< The delay until the timer fires for the first time
|
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
|
u64 interval_delay; ///< The delay until the timer fires after the first time
|
||||||
|
|
||||||
ResultVal<bool> ShouldWait() override {
|
bool ShouldWait() override {
|
||||||
return MakeResult<bool>(!signaled);
|
return !signaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<bool> Acquire() override {
|
void Acquire() override {
|
||||||
return MakeResult<bool>(true);
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -122,10 +122,8 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
|
||||||
LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle,
|
LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle,
|
||||||
object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds);
|
object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds);
|
||||||
|
|
||||||
ResultVal<bool> wait = object->ShouldWait();
|
|
||||||
|
|
||||||
// Check for next thread to schedule
|
// Check for next thread to schedule
|
||||||
if (wait.Succeeded() && *wait) {
|
if (object->ShouldWait()) {
|
||||||
|
|
||||||
object->AddWaitingThread(Kernel::GetCurrentThread());
|
object->AddWaitingThread(Kernel::GetCurrentThread());
|
||||||
Kernel::WaitCurrentThread_WaitSynchronization(object);
|
Kernel::WaitCurrentThread_WaitSynchronization(object);
|
||||||
|
@ -138,7 +136,7 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
|
||||||
object->Acquire();
|
object->Acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
return wait.Code().raw;
|
return RESULT_SUCCESS.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
|
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
|
||||||
|
@ -167,10 +165,8 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
|
||||||
if (object == nullptr)
|
if (object == nullptr)
|
||||||
return InvalidHandle(ErrorModule::Kernel).raw;
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
||||||
|
|
||||||
ResultVal<bool> wait = object->ShouldWait();
|
|
||||||
|
|
||||||
// Check if the current thread should wait on this object...
|
// Check if the current thread should wait on this object...
|
||||||
if (wait.Succeeded() && *wait) {
|
if (object->ShouldWait()) {
|
||||||
|
|
||||||
// Check we are waiting on all objects...
|
// Check we are waiting on all objects...
|
||||||
if (wait_all)
|
if (wait_all)
|
||||||
|
|
Loading…
Reference in a new issue