Skip to content

Commit

Permalink
Plugins: Schedule plugins before game thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Sep 8, 2020
1 parent 2f4945a commit ac7522b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
12 changes: 8 additions & 4 deletions Core/HLE/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct PluginInfo {
PluginType type;
std::string filename;
int version;
int memory;
uint32_t memory;
};

static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) {
Expand Down Expand Up @@ -162,17 +162,18 @@ void Init() {
}
}

void Load() {
bool Load() {
bool started = false;
for (const std::string &filename : prxPlugins) {
std::string error_string = "";
SceUID module = KernelLoadModule(filename, &error_string);
if (!error_string.empty()) {
ERROR_LOG(SYSTEM, "Unable to load plugin %s: %s", filename.c_str(), error_string.c_str());
return;
continue;
}
if (module < 0) {
ERROR_LOG(SYSTEM, "Unable to load plugin %s: %08x", filename.c_str(), module);
return;
continue;
}

int ret = KernelStartModule(module, 0, 0, 0, nullptr, nullptr);
Expand All @@ -181,7 +182,10 @@ void Load() {
}

INFO_LOG(SYSTEM, "Loaded plugin: %s", filename.c_str());
started = true;
}

return started;
}

void Unload() {
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/Plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace HLEPlugins {
void Init();
void Shutdown();

void Load();
bool Load();
void Unload();

void DoState(PointerWrap &p);
Expand Down
5 changes: 4 additions & 1 deletion Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,10 @@ static void __KernelStartModule(PSPModule *m, int args, const char *argp, SceKer
SceUID threadID = __KernelSetupRootThread(m->GetUID(), args, argp, options->priority, options->stacksize, options->attribute);
__KernelSetThreadRA(threadID, NID_MODULERETURN);

HLEPlugins::Load();
if (HLEPlugins::Load()) {
KernelRotateThreadReadyQueue(0);
__KernelReSchedule("Started plugins");
}
}


Expand Down
22 changes: 12 additions & 10 deletions Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,10 +2246,7 @@ bool __KernelIsDispatchEnabled()
return dispatchEnabled && __InterruptsEnabled();
}

int sceKernelRotateThreadReadyQueue(int priority)
{
VERBOSE_LOG(SCEKERNEL, "sceKernelRotateThreadReadyQueue(%x)", priority);

int KernelRotateThreadReadyQueue(int priority) {
PSPThread *cur = __GetCurrentThread();

// 0 is special, it means "my current priority."
Expand All @@ -2259,11 +2256,9 @@ int sceKernelRotateThreadReadyQueue(int priority)
if (priority <= 0x07 || priority > 0x77)
return SCE_KERNEL_ERROR_ILLEGAL_PRIORITY;

if (!threadReadyQueue.empty(priority))
{
if (!threadReadyQueue.empty(priority)) {
// In other words, yield to everyone else.
if (cur->nt.currentPriority == priority)
{
if (cur->nt.currentPriority == priority) {
threadReadyQueue.push_back(priority, currentThread);
cur->nt.status = (cur->nt.status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY;
}
Expand All @@ -2272,11 +2267,18 @@ int sceKernelRotateThreadReadyQueue(int priority)
threadReadyQueue.rotate(priority);
}

hleReSchedule("rotatethreadreadyqueue");
hleEatCycles(250);
return 0;
}

int sceKernelRotateThreadReadyQueue(int priority) {
int result = KernelRotateThreadReadyQueue(priority);
if (result == 0) {
hleReSchedule("rotatethreadreadyqueue");
hleEatCycles(250);
}
return hleLogSuccessVerboseI(SCEKERNEL, result);
}

int sceKernelDeleteThread(int threadID) {
if (threadID == 0 || threadID == currentThread) {
ERROR_LOG(SCEKERNEL, "sceKernelDeleteThread(%i): cannot delete current thread", threadID);
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/sceKernelThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ u32 sceKernelReferThreadRunStatus(u32 uid, u32 statusPtr);
int sceKernelReleaseWaitThread(SceUID threadID);
int sceKernelChangeCurrentThreadAttr(u32 clearAttr, u32 setAttr);
int sceKernelRotateThreadReadyQueue(int priority);
int KernelRotateThreadReadyQueue(int priority);
int sceKernelCheckThreadStack();
int sceKernelSuspendThread(SceUID threadID);
int sceKernelResumeThread(SceUID threadID);
Expand Down

0 comments on commit ac7522b

Please sign in to comment.