This commit is contained in:
citrabot 2017-01-07 06:00:03 +00:00
commit 6cc8620182
4 changed files with 21 additions and 2 deletions

View file

@ -35,7 +35,8 @@ bool Semaphore::ShouldWait(Thread* thread) const {
}
void Semaphore::Acquire(Thread* thread) {
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
if (available_count <= 0)
return;
--available_count;
}

View file

@ -508,6 +508,10 @@ SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) {
return thread;
}
bool HaveReadyThreads() {
return ready_queue.get_first() != nullptr;
}
void Reschedule() {
Thread* cur = GetCurrentThread();
Thread* next = PopNextReadyThread();

View file

@ -218,6 +218,11 @@ private:
*/
SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority);
/**
* Returns whether there are any threads that are ready to run.
*/
bool HaveReadyThreads();
/**
* Reschedules to the next available thread (call after current thread is suspended)
*/

View file

@ -849,6 +849,11 @@ static ResultCode CancelTimer(Kernel::Handle handle) {
static void SleepThread(s64 nanoseconds) {
LOG_TRACE(Kernel_SVC, "called nanoseconds=%lld", nanoseconds);
// Don't attempt to yield execution if there are no available threads to run,
// this way we avoid a useless reschedule to the idle thread.
if (nanoseconds == 0 && !Kernel::HaveReadyThreads())
return;
// Sleep current thread and check for next thread to schedule
Kernel::WaitCurrentThread_Sleep();
@ -897,7 +902,11 @@ static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 si
return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS,
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
if (addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) {
// TODO(Subv): Processes with memory type APPLICATION are not allowed
// to create memory blocks with addr = 0, any attempts to do so
// should return error 0xD92007EA.
if ((addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) &&
addr != 0) {
return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS,
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
}