static int SubThread(SceSize args, void *argp) { int error, numWaitThreads; SceKernelMbxInfo info; /* For simplicily, we statically allocate some messages */ static MyMessage one = { {0}, "One" }; static MyMessage two = { {0}, "Two" }; static MyMessage three = { {0}, "Three" }; sceKernelDelayThread(100000); printf("SUB: started\n"); sceKernelDelayThread(1000000); /* Send a message */ printf("SUB: Posting 1\n"); sceKernelSendMbx(myMessagebox, &one.header); /* Send another message after some delay, to demonstrate the timeout feature */ sceKernelDelayThread(1000000); printf("SUB: Posting 2\n"); sceKernelSendMbx(myMessagebox, &two.header); /* Again, send another message after some delay, this time to demonstrate the polling feature */ sceKernelDelayThread(1000000); printf("SUB: Posting 3\n"); sceKernelSendMbx(myMessagebox, &three.header); /* Wait for the main task to start blocking again, and then check the messagebox status */ sceKernelDelayThread(1000000); printf("SUB: Checking messagebox status\n"); info.size = sizeof(info); error = sceKernelReferMbxStatus(myMessagebox, &info); if(error < 0) printf("SUB: ERROR %08x\n", error); else printf("SUB: status ok, name=\"%s\", attr=%d, numWaitThreads=%d, " "numMessages=%d, firstMessage=%p\n", info.name, info.attr, info.numWaitThreads, info.numMessages, info.firstMessage); /* Finally, cancel the main tasks receive operation */ printf("SUB: Cancelling receive\n"); error = sceKernelCancelReceiveMbx(myMessagebox, &numWaitThreads); sceKernelDelayThread(100000); if(error < 0) printf("SUB: ERROR %08x\n", error); else printf("SUB: cancellation ok, %d threads were waiting\n", numWaitThreads); printf("SUB: Exiting\n"); return 0; }
void stop_gdb(void) { if(g_thid > 0) { sceKernelSuspendThread(g_thid); } /* Cancel mbx receive, should then force the thread to exit */ sceKernelCancelReceiveMbx(g_handler.mbox, NULL); }