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 printMbxStatus(SceUID mbxId) { SceKernelMbxInfo mbxInfo; int result; memset(&mbxInfo, 0, sizeof(mbxInfo)); mbxInfo.size = sizeof(mbxInfo); result = sceKernelReferMbxStatus(mbxId, &mbxInfo); if (result != 0) { pspDebugScreenPrintf("sceKernelReferMbxStatus returning 0x%08X\n", result); return; } pspDebugScreenPrintf("sceKernelReferMbxStatus mbxId=0x%08X:\n", mbxId); pspDebugScreenPrintf(" name = '%s'\n", mbxInfo.name); pspDebugScreenPrintf(" attr = 0x%X\n", mbxInfo.attr); pspDebugScreenPrintf(" numWaitThreads = %d\n", (int) mbxInfo.numWaitThreads); pspDebugScreenPrintf(" numMessages = %d\n", (int) mbxInfo.numMessages); pspDebugScreenPrintf(" firstMessage = 0x%08X\n", (int) mbxInfo.firstMessage); }