Slowly Cleanup (#1213)

* Add slowly.h

* Init and destroy

* File header
This commit is contained in:
Derek Hensley
2023-03-19 06:48:49 -07:00
committed by GitHub
parent 6ff77ab092
commit 03c8d46ed2
8 changed files with 76 additions and 51 deletions
+5 -4
View File
@@ -1,4 +1,5 @@
#include "global.h"
#include "slowly.h"
#include "stack.h"
/**
@@ -411,7 +412,7 @@ void PreRender_ApplyFilters(PreRender* this) {
}
}
extern SlowlyTask D_801F6E00;
extern SlowlyMgr sSlowlyMgr;
extern s32 D_801F6FC0;
extern StackEntry sSlowlyStackInfo;
extern STACK(sSlowlyStack, 0x1000);
@@ -423,12 +424,12 @@ void PreRender_ApplyFiltersSlowlyInit(PreRender* this) {
if ((this->cvgSave != NULL) && (this->fbufSave != NULL)) {
if (D_801F6FC0) {
StackCheck_Cleanup(&sSlowlyStackInfo);
Slowly_Stop(&D_801F6E00);
Slowly_Destroy(&sSlowlyMgr);
}
this->unk_4D = 1;
StackCheck_Init(&sSlowlyStackInfo, sSlowlyStack, STACK_TOP(sSlowlyStack), 0, 0x100, "slowly");
Slowly_Start(&D_801F6E00, STACK_TOP(sSlowlyStack), PreRender_ApplyFilters, this, NULL);
Slowly_Init(&sSlowlyMgr, STACK_TOP(sSlowlyStack), (void*)PreRender_ApplyFilters, this, NULL);
D_801F6FC0 = true;
}
}
@@ -439,7 +440,7 @@ void PreRender_ApplyFiltersSlowlyInit(PreRender* this) {
void PreRender_ApplyFiltersSlowlyDestroy(PreRender* this) {
if (D_801F6FC0) {
StackCheck_Cleanup(&sSlowlyStackInfo);
Slowly_Stop(&D_801F6E00);
Slowly_Destroy(&sSlowlyMgr);
D_801F6FC0 = false;
}
}
+34 -19
View File
@@ -1,43 +1,58 @@
/**
* @file sys_slowly.c
*
* This file implements a manager for running an asynchronous task on a thread with the lowest priority.
*
* The task callback is expected to have up to 2 void* arguments and have a void return. Setting `argCount` will adjust
* how many args the callback gets called with, but defaults to 2 and using the 2 argument callback.
*
* @note: `argCount` must be set manually, as this file implements no way to configure it.
*/
#include "slowly.h"
#include "global.h"
#define SLOWLY_STATUS_DONE (1 << 0)
#define SLOWLY_STATUS_STARTED (1 << 1)
void Slowly_Main(SlowlyTask* slowly) {
void Slowly_Main(SlowlyMgr* slowly) {
slowly->status |= SLOWLY_STATUS_STARTED;
switch (slowly->callbackArgCount) {
case SLOWLY_CALLBACK_NO_ARGS:
slowly->callback0();
switch (slowly->argCount) {
case 0:
slowly->callback.zero();
break;
case SLOWLY_CALLBACK_ONE_ARG:
slowly->callback1(slowly->callbackArg0);
case 1:
slowly->callback.one(slowly->arg0);
break;
case SLOWLY_CALLBACK_TWO_ARGS:
slowly->callback2(slowly->callbackArg0, slowly->callbackArg1);
case 2:
slowly->callback.two(slowly->arg0, slowly->arg1);
break;
default:
break;
}
slowly->status |= SLOWLY_STATUS_DONE;
}
void Slowly_ThreadEntry(SlowlyTask* slowly) {
void Slowly_ThreadEntry(void* arg) {
SlowlyMgr* slowly = (SlowlyMgr*)arg;
Slowly_Main(slowly);
}
void Slowly_Start(SlowlyTask* slowly, void* stack, void (*callback)(), void* callbackArg0, void* callbackArg1) {
bzero(slowly, sizeof(SlowlyTask));
void Slowly_Init(SlowlyMgr* slowly, void* stack, SlowlyCallbackTwo callback, void* arg0, void* arg1) {
bzero(slowly, sizeof(SlowlyMgr));
slowly->callbackArgCount = SLOWLY_CALLBACK_TWO_ARGS;
slowly->argCount = 2;
slowly->status = 0;
slowly->callback0 = callback;
slowly->callbackArg0 = callbackArg0;
slowly->callbackArg1 = callbackArg1;
slowly->callback.two = callback;
slowly->arg0 = arg0;
slowly->arg1 = arg1;
osCreateThread(&slowly->thread, Z_THREAD_ID_SLOWLY, Slowly_ThreadEntry, slowly, stack, Z_PRIORITY_SLOWLY);
osStartThread(&slowly->thread);
}
void Slowly_Stop(SlowlyTask* slowly) {
void Slowly_Destroy(SlowlyMgr* slowly) {
osDestroyThread(&slowly->thread);
}