libctru  v2.3.1
threads/event/source/main.c
#include <string.h>
#include <malloc.h>
#include <inttypes.h>
#include <stdio.h>
#include <3ds.h>
Thread threadHandle;
Handle threadRequest;
#define STACKSIZE (4 * 1024)
volatile bool runThread = true;
volatile int threadcount=0;
void threadMain(void *arg) {
while(runThread) {
svcClearEvent(threadRequest);
threadcount++;
}
}
int main(int argc, char** argv)
{
svcCreateEvent(&threadRequest,0);
threadHandle = threadCreate(threadMain, 0, STACKSIZE, 0x3f, -2, true);
printf("thread handle: %p\n", threadHandle);
// Main loop
while (aptMainLoop())
{
printf("\x1b[6;1H");
printf("thread counter = %d\n",threadcount);
u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break; // break in order to return to hbmenu
if (kDown & KEY_A)
svcSignalEvent(threadRequest);
// Flush and swap framebuffers
}
// tell thread to exit
runThread = false;
// signal the thread and wait for it to exit
svcSignalEvent(threadRequest);
threadJoin(threadHandle, U64_MAX);
// close event handle
svcCloseHandle(threadRequest);
return 0;
}
Central 3DS header.
bool aptMainLoop(void)
Main function which handles sleep mode and HOME/power buttons - call this at the beginning of every f...
PrintConsole * consoleInit(gfxScreen_t screen, PrintConsole *console)
Initialise the console.
void gfxSwapBuffers(void)
Updates the configuration of both screens.
void gfxInitDefault(void)
Initializes the LCD framebuffers with default parameters This is equivalent to calling:
@ GFX_TOP
Top screen.
Definition: gfx.h:26
void gfxExit(void)
Deinitializes and frees the LCD framebuffers.
void gfxFlushBuffers(void)
Flushes the data cache for the current framebuffers.
#define gspWaitForVBlank()
Waits for VBlank.
Definition: gspgpu.h:151
@ KEY_START
Start.
Definition: hid.h:15
@ KEY_A
A.
Definition: hid.h:12
u32 hidKeysDown(void)
Returns a bitmask of newly pressed buttons, this frame.
void hidScanInput(void)
Scans HID for input data.
Result svcCloseHandle(Handle handle)
Closes a handle.
Result svcWaitSynchronization(Handle handle, s64 nanoseconds)
Waits for synchronization on a handle.
Result svcCreateEvent(Handle *event, ResetType reset_type)
Creates an event handle.
Result svcClearEvent(Handle handle)
Clears an event.
Result svcSignalEvent(Handle handle)
Signals an event.
struct Thread_tag * Thread
libctru thread handle type
Definition: thread.h:22
Thread threadCreate(ThreadFunc entrypoint, void *arg, size_t stack_size, int prio, int core_id, bool detached)
Creates a new libctru thread.
Result threadJoin(Thread thread, u64 timeout_ns)
Waits for a libctru thread to finish (or returns immediately if it is already finished).
#define U64_MAX
The maximum value of a u64.
Definition: types.h:12
u32 Handle
Resource handle.
Definition: types.h:41
uint32_t u32
32-bit unsigned integer
Definition: types.h:23