#include <3ds.h>
-Handle threadHandle, threadRequest;
+Thread threadHandle;
+Handle threadRequest;
#define STACKSIZE (4 * 1024)
-volatile bool threadExit = false;
+volatile bool runThread = true;
volatile int threadcount=0;
void threadMain(void *arg) {
- while(1) {
+ while(runThread) {
svcWaitSynchronization(threadRequest, U64_MAX);
- svcClearEvent(threadRequest);
-
- if(threadExit) svcExitThread();
+ svcClearEvent(threadRequest);
threadcount++;
}
}
-int main(int argc, char** argv) {
-
-
+int main(int argc, char** argv)
+{
gfxInitDefault();
-
consoleInit(GFX_TOP, NULL);
-
svcCreateEvent(&threadRequest,0);
- u32 *threadStack = memalign(32, STACKSIZE);
- Result ret = svcCreateThread(&threadHandle, threadMain, 0, &threadStack[STACKSIZE/4], 0x3f, 0);
+ threadHandle = threadCreate(threadMain, 0, STACKSIZE, 0x3f, -2, true);
- printf("thread create returned %lx\n", ret);
+ printf("thread handle: %p\n", threadHandle);
// Main loop
while (aptMainLoop())
}
// tell thread to exit
- threadExit = true;
+ runThread = false;
- // signal the thread
+ // signal the thread and wait for it to exit
svcSignalEvent(threadRequest);
+ threadJoin(threadHandle, U64_MAX);
- // give it time to exit
- svcSleepThread(10000000ULL);
-
- // close handles and free allocated stack
+ // close event handle
svcCloseHandle(threadRequest);
- svcCloseHandle(threadHandle);
- free(threadStack);
-
gfxExit();
return 0;
#include <3ds/services/cfgu.h>
#include <3ds/services/fs.h>
#include <3ds/env.h>
+#include <3ds/thread.h>
#define NDSP_THREAD_STACK_SIZE 0x1000
static u8 dspVar5Backup[0x1080];
static volatile bool ndspThreadRun;
-static Handle ndspThread;
-static u64 ndspThreadStack[NDSP_THREAD_STACK_SIZE/8]; // u64 so that it's 8-byte aligned
+static Thread ndspThread;
static Result ndspLoadComponent(void)
{
frameCount++;
bNeedsSync = true;
}
-
- svcExitThread();
}
void ndspUseComponent(const void* binary, u32 size, u16 progMask, u16 dataMask)
rc = svcCreateEvent(&sleepEvent, 0);
if (R_FAILED(rc)) goto _fail2;
- rc = svcCreateThread(&ndspThread, ndspThreadMain, 0x0, (u32*)(&ndspThreadStack[NDSP_THREAD_STACK_SIZE/8]), 0x31, -2);
- if (R_FAILED(rc)) goto _fail3;
+ ndspThread = threadCreate(ndspThreadMain, 0x0, NDSP_THREAD_STACK_SIZE, 0x31, -2, true);
+ if (!ndspThread) goto _fail3;
aptHook(&aptCookie, ndspAptHook, NULL);
return 0;
ndspThreadRun = false;
if (bSleeping)
svcSignalEvent(sleepEvent);
- svcWaitSynchronization(ndspThread, U64_MAX);
- svcCloseHandle(ndspThread);
+ threadJoin(ndspThread, U64_MAX);
svcCloseHandle(sleepEvent);
aptUnhook(&aptCookie);
if (!bSleeping)
#include <3ds/services/gspgpu.h>
#include <3ds/ipc.h>
#include <3ds/env.h>
+#include <3ds/thread.h>
#define APT_HANDLER_STACKSIZE (0x1000)
Handle aptuHandle;
Handle aptEvents[3];
-Handle aptEventHandlerThread;
-u64 aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]; // u64 so that it's 8-byte aligned
+Thread aptEventHandlerThread;
LightLock aptStatusMutex;
Handle aptStatusEvent;
break;
}
}
-
- svcExitThread();
}
static int aptRefCount = 0;
aptCloseSession();
// create APT event handler thread
- svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0,
- (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
+ aptEventHandlerThread = threadCreate(aptEventHandler, 0x0, APT_HANDLER_STACKSIZE, 0x31, -2, true);
// Wait for the state to become APT_RUNNING
aptWaitStatusEvent();
}
svcSignalEvent(aptEvents[2]);
- svcWaitSynchronization(aptEventHandlerThread, U64_MAX);
- svcCloseHandle(aptEventHandlerThread);
+ threadJoin(aptEventHandlerThread, U64_MAX);
svcCloseHandle(aptEvents[2]);
svcCloseHandle(aptSleepSync);
#include <3ds/synchronization.h>
#include <3ds/services/gspgpu.h>
#include <3ds/ipc.h>
+#include <3ds/thread.h>
#define GSP_EVENT_STACK_SIZE 0x1000
Handle gspEvents[GSPGPU_EVENT_MAX];
vu32 gspEventCounts[GSPGPU_EVENT_MAX];
-u64 gspEventStack[GSP_EVENT_STACK_SIZE/sizeof(u64)]; //u64 so that it's 8-byte aligned
volatile bool gspRunEvents;
-Handle gspEventThread;
+Thread gspEventThread;
static Handle gspEvent;
static vu8* gspEventData;
gspEvent = _gspEvent;
gspEventData = _gspSharedMem + gspThreadId*0x40;
gspRunEvents = true;
- return svcCreateThread(&gspEventThread, gspEventThreadMain, 0x0, (u32*)((char*)gspEventStack + sizeof(gspEventStack)), 0x31, 0xfffffffe);
+ gspEventThread = threadCreate(gspEventThreadMain, 0x0, GSP_EVENT_STACK_SIZE, 0x31, -2, true);
+ return 0;
}
void gspExitEventHandler(void)
{
// Stop event thread
gspRunEvents = false;
- svcWaitSynchronization(gspEventThread, 1000000000);
- svcCloseHandle(gspEventThread);
+ svcSignalEvent(gspEvent);
+ threadJoin(gspEventThread, U64_MAX);
// Free events
int i;
}
}
}
- svcExitThread();
}
//essentially : get commandIndex and totalCommands, calculate offset of new command, copy command and update totalCommands