summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2014-05-13 22:29:31 -0400
committerGravatar bunnei2014-05-13 22:29:31 -0400
commit7d078189daec2db8a465a401b6867739fea5043d (patch)
tree353f1fc1c9b5f1e62637b86a82eb75f73066441c /src/core
parentadded a bunch of threading code, recycled from PPSSPP, with lots of hacks in ... (diff)
downloadyuzu-7d078189daec2db8a465a401b6867739fea5043d.tar.gz
yuzu-7d078189daec2db8a465a401b6867739fea5043d.tar.xz
yuzu-7d078189daec2db8a465a401b6867739fea5043d.zip
various cleanups / remove unused code
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/kernel/thread.cpp93
-rw-r--r--src/core/hle/kernel/thread.h1
2 files changed, 29 insertions, 65 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 584276eec..95ef2c173 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -427,10 +427,11 @@ std::vector<UID> g_thread_queue;
427// Lists only ready thread ids 427// Lists only ready thread ids
428ThreadQueueList g_thread_ready_queue; 428ThreadQueueList g_thread_ready_queue;
429 429
430UID g_current_thread; 430UID g_current_thread = 0;
431Thread* g_current_thread_ptr; 431Thread* g_current_thread_ptr = NULL;
432const char *g_hle_current_thread_name = NULL; 432const char* g_hle_current_thread_name = NULL;
433 433
434/// Creates a new thread
434Thread* __KernelCreateThread(UID& id, UID module_id, const char* name, u32 priority, 435Thread* __KernelCreateThread(UID& id, UID module_id, const char* name, u32 priority,
435 u32 entrypoint, u32 arg, u32 stack_top, u32 processor_id, int stack_size) { 436 u32 entrypoint, u32 arg, u32 stack_top, u32 processor_id, int stack_size) {
436 437
@@ -459,38 +460,25 @@ Thread* __KernelCreateThread(UID& id, UID module_id, const char* name, u32 prior
459 return t; 460 return t;
460} 461}
461 462
463/// Resets the specified thread back to initial calling state
462void __KernelResetThread(Thread *t, int lowest_priority) { 464void __KernelResetThread(Thread *t, int lowest_priority) {
463 t->context.reset(); 465 t->context.reset();
464 t->context.pc = t->nt.entry_point; 466 t->context.pc = t->nt.entry_point;
465 467
466 // If the thread would be better than lowestPriority, reset to its initial. Yes, kinda odd... 468 // If the thread would be better than lowestPriority, reset to its initial. Yes, kinda odd...
467 if (t->nt.current_priority < lowest_priority) 469 if (t->nt.current_priority < lowest_priority) {
468 t->nt.current_priority = t->nt.initial_priority; 470 t->nt.current_priority = t->nt.initial_priority;
471 }
469 472
470 //t->nt.wait_type = WAITTYPE_NONE;
471 //t->nt.wait_id = 0;
472 memset(&t->waitInfo, 0, sizeof(t->waitInfo)); 473 memset(&t->waitInfo, 0, sizeof(t->waitInfo));
473
474 //t->nt.exitStatus = SCE_KERNEL_ERROR_NOT_DORMANT;
475 //t->isProcessingCallbacks = false;
476 //t->currentCallbackId = 0;
477 //t->currentMipscallId = 0;
478 //t->pendingMipsCalls.clear();
479
480 //t->context.r[MIPS_REG_RA] = threadReturnHackAddr; //hack! TODO fix
481 // TODO: Not sure if it's reset here, but this makes sense.
482 //t->context.r[MIPS_REG_GP] = t->nt.gpreg;
483 //t->FillStack();
484
485 //if (!t->waitingThreads.empty())
486 // ERROR_LOG(KERNEL, "Resetting thread with threads waiting on end?");
487} 474}
488 475
489 476/// Returns the current executing thread
490inline Thread *__GetCurrentThread() { 477inline Thread *__GetCurrentThread() {
491 return g_current_thread_ptr; 478 return g_current_thread_ptr;
492} 479}
493 480
481/// Sets the current executing thread
494inline void __SetCurrentThread(Thread *thread, UID thread_id, const char *name) { 482inline void __SetCurrentThread(Thread *thread, UID thread_id, const char *name) {
495 g_current_thread = thread_id; 483 g_current_thread = thread_id;
496 g_current_thread_ptr = thread; 484 g_current_thread_ptr = thread;
@@ -526,30 +514,29 @@ void __KernelChangeReadyState(UID thread_id, bool ready) {
526 } 514 }
527} 515}
528 516
529// Returns NULL if the current thread is fine. 517/// Returns NULL if the current thread is fine.
530Thread* __KernelNextThread() { 518Thread* __KernelNextThread() {
531 UID bestThread; 519 UID best_thread;
532 520
533 // If the current thread is running, it's a valid candidate. 521 // If the current thread is running, it's a valid candidate.
534 Thread *cur = __GetCurrentThread(); 522 Thread *cur = __GetCurrentThread();
535 if (cur && cur->IsRunning()) { 523 if (cur && cur->IsRunning()) {
536 bestThread = g_thread_ready_queue.pop_first_better(cur->nt.current_priority); 524 best_thread = g_thread_ready_queue.pop_first_better(cur->nt.current_priority);
537 if (bestThread != 0) { 525 if (best_thread != 0) {
538 __KernelChangeReadyState(cur, g_current_thread, true); 526 __KernelChangeReadyState(cur, g_current_thread, true);
539 } 527 }
540 } else { 528 } else {
541 bestThread = g_thread_ready_queue.pop_first(); 529 best_thread = g_thread_ready_queue.pop_first();
542 } 530 }
543
544 // Assume g_thread_ready_queue has not become corrupt. 531 // Assume g_thread_ready_queue has not become corrupt.
545 if (bestThread != 0) { 532 if (best_thread != 0) {
546 return g_kernel_objects.GetFast<Thread>(bestThread); 533 return g_kernel_objects.GetFast<Thread>(best_thread);
547 } else { 534 } else {
548 return NULL; 535 return NULL;
549 } 536 }
550} 537}
551 538
552// Saves the current CPU context 539/// Saves the current CPU context
553void __KernelSaveContext(ThreadContext *ctx) { 540void __KernelSaveContext(ThreadContext *ctx) {
554 ctx->reg[0] = Core::g_app_core->GetReg(0); 541 ctx->reg[0] = Core::g_app_core->GetReg(0);
555 ctx->reg[1] = Core::g_app_core->GetReg(1); 542 ctx->reg[1] = Core::g_app_core->GetReg(1);
@@ -571,7 +558,7 @@ void __KernelSaveContext(ThreadContext *ctx) {
571 ctx->cpsr = Core::g_app_core->GetCPSR(); 558 ctx->cpsr = Core::g_app_core->GetCPSR();
572} 559}
573 560
574// Loads a CPU context 561/// Loads a CPU context
575void __KernelLoadContext(ThreadContext *ctx) { 562void __KernelLoadContext(ThreadContext *ctx) {
576 Core::g_app_core->SetReg(0, ctx->reg[0]); 563 Core::g_app_core->SetReg(0, ctx->reg[0]);
577 Core::g_app_core->SetReg(1, ctx->reg[1]); 564 Core::g_app_core->SetReg(1, ctx->reg[1]);
@@ -593,59 +580,35 @@ void __KernelLoadContext(ThreadContext *ctx) {
593 Core::g_app_core->SetCPSR(ctx->cpsr); 580 Core::g_app_core->SetCPSR(ctx->cpsr);
594} 581}
595 582
583/// Switches thread context
596void __KernelSwitchContext(Thread *target, const char *reason) { 584void __KernelSwitchContext(Thread *target, const char *reason) {
597 u32 oldPC = 0; 585 u32 old_pc = 0;
598 UID oldUID = 0; 586 UID old_uid = 0;
599 const char *oldName = g_hle_current_thread_name != NULL ? g_hle_current_thread_name : "(none)"; 587 const char *old_name = g_hle_current_thread_name != NULL ? g_hle_current_thread_name : "(none)";
600
601 Thread *cur = __GetCurrentThread(); 588 Thread *cur = __GetCurrentThread();
589
602 if (cur) { // It might just have been deleted. 590 if (cur) { // It might just have been deleted.
603 __KernelSaveContext(&cur->context); 591 __KernelSaveContext(&cur->context);
604 oldPC = Core::g_app_core->GetPC(); 592 old_pc = Core::g_app_core->GetPC();
605 oldUID = cur->GetUID(); 593 old_uid = cur->GetUID();
606 594
607 // Normally this is taken care of in __KernelNextThread(). 595 // Normally this is taken care of in __KernelNextThread().
608 if (cur->IsRunning()) 596 if (cur->IsRunning())
609 __KernelChangeReadyState(cur, oldUID, true); 597 __KernelChangeReadyState(cur, old_uid, true);
610 } 598 }
611
612 if (target) { 599 if (target) {
613 __SetCurrentThread(target, target->GetUID(), target->nt.name); 600 __SetCurrentThread(target, target->GetUID(), target->nt.name);
614 __KernelChangeReadyState(target, g_current_thread, false); 601 __KernelChangeReadyState(target, g_current_thread, false);
602
615 target->nt.status = (target->nt.status | THREADSTATUS_RUNNING) & ~THREADSTATUS_READY; 603 target->nt.status = (target->nt.status | THREADSTATUS_RUNNING) & ~THREADSTATUS_READY;
616 604
617 __KernelLoadContext(&target->context); 605 __KernelLoadContext(&target->context);
618 } else { 606 } else {
619 __SetCurrentThread(NULL, 0, NULL); 607 __SetCurrentThread(NULL, 0, NULL);
620 } 608 }
621
622#if DEBUG_LEVEL <= MAX_LOGLEVEL || DEBUG_LOG == NOTICE_LOG
623 //bool fromIdle = oldUID == threadIdleID[0] || oldUID == threadIdleID[1];
624 //bool toIdle = currentThread == threadIdleID[0] || currentThread == threadIdleID[1];
625 //if (!(fromIdle && toIdle))
626 //{
627 // u64 nowCycles = CoreTiming::GetTicks();
628 // s64 consumedCycles = nowCycles - lastSwitchCycles;
629 // lastSwitchCycles = nowCycles;
630
631 // DEBUG_LOG(SCEKERNEL, "Context switch: %s -> %s (%i->%i, pc: %08x->%08x, %s) +%lldus",
632 // oldName, hleCurrentThreadName,
633 // oldUID, currentThread,
634 // oldPC, currentMIPS->pc,
635 // reason,
636 // cyclesToUs(consumedCycles));
637 //}
638#endif
639
640 if (target) {
641 //// No longer waiting.
642 //target->nt.waitType = WAITTYPE_NONE;
643 //target->nt.waitID = 0;
644
645 //__KernelExecutePendingARMCalls(target, true);
646 }
647} 609}
648 610
611/// Sets up the root (primary) thread of execution
649UID __KernelSetupRootThread(UID module_id, int arg, int prio, int stack_size) { 612UID __KernelSetupRootThread(UID module_id, int arg, int prio, int stack_size) {
650 UID id; 613 UID id;
651 614
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 38180cb9b..1731248cc 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "core/hle/kernel/kernel.h"
8 9
9enum ThreadStatus { 10enum ThreadStatus {
10 THREADSTATUS_RUNNING = 1, 11 THREADSTATUS_RUNNING = 1,