libctru/examples/threads/event/source/main.c

72 lines
1.2 KiB
C
Raw Normal View History

2015-02-25 16:28:30 +01:00
#include <string.h>
#include <malloc.h>
#include <inttypes.h>
#include <stdio.h>
#include <3ds.h>
Thread threadHandle;
Handle threadRequest;
2015-02-25 16:28:30 +01:00
#define STACKSIZE (4 * 1024)
volatile bool runThread = true;
2015-02-25 16:28:30 +01:00
volatile int threadcount=0;
void threadMain(void *arg) {
while(runThread) {
2015-02-25 16:28:30 +01:00
svcWaitSynchronization(threadRequest, U64_MAX);
svcClearEvent(threadRequest);
2015-02-25 16:28:30 +01:00
threadcount++;
}
}
int main(int argc, char** argv)
{
2015-02-25 16:28:30 +01:00
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
svcCreateEvent(&threadRequest,0);
threadHandle = threadCreate(threadMain, 0, STACKSIZE, 0x3f, -2, true);
2015-02-25 16:28:30 +01:00
printf("thread handle: %p\n", threadHandle);
2015-02-25 16:28:30 +01:00
// Main loop
while (aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();
printf("\x1b[5;0H");
printf("thread counter = %d\n",threadcount);
u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break; // break in order to return to hbmenu
2015-02-26 09:37:23 +01:00
if (kDown & KEY_A)
2015-02-25 16:28:30 +01:00
svcSignalEvent(threadRequest);
// Flush and swap framebuffers
gfxFlushBuffers();
gfxSwapBuffers();
}
// tell thread to exit
runThread = false;
2015-02-25 16:28:30 +01:00
// signal the thread and wait for it to exit
2015-02-25 16:28:30 +01:00
svcSignalEvent(threadRequest);
threadJoin(threadHandle, U64_MAX);
2015-02-25 16:28:30 +01:00
// close event handle
2015-02-25 16:28:30 +01:00
svcCloseHandle(threadRequest);
gfxExit();
return 0;
}