5 #include <pspthreadman.h>
7 typedef void (*entrypoint_t)(void);
9 cothread_t co_active(void)
11 return (void *)sceKernelGetThreadId();
14 static int thread_wrap(unsigned int argc, void *argp)
16 entrypoint_t entrypoint = *(entrypoint_t *) argp;
17 sceKernelSleepThread();
22 cothread_t co_create(unsigned int size, void (*entrypoint)(void))
24 SceUID new_thread_id = sceKernelCreateThread("cothread", thread_wrap, 0x12, size, 0, NULL);
25 sceKernelStartThread(new_thread_id, sizeof (entrypoint), &entrypoint);
26 return (void *) new_thread_id;
29 void co_delete(cothread_t handle)
31 SceUID id = (SceUID) handle;
32 sceKernelTerminateDeleteThread(id);
35 void co_switch(cothread_t handle)
37 SceUID id = (SceUID) handle;
38 sceKernelWakeupThread(id);
39 /* Sleep the currently active thread so the new thread can start */
40 sceKernelSleepThread();