int main(int argc, char **argv) { OSMessage msg; int i; OSInitMessageQueue(&sQueue, sMessages, NumMessages); OSCreateThread(&sThread, msgThreadEntry, 0, NULL, sThreadStack + StackSize, StackSize, 20, 0); OSResumeThread(&sThread); // Make sure other thread gets to a blocking read OSSleepTicks(OSMillisecondsToTicks(10)); // Sending message into empty queue should succeed. for (i = 0; i < NumMessages; ++i) { msg.message = (void *)1; msg.args[0] = 2 + i; msg.args[1] = 3; msg.args[2] = 4; test_eq(OSSendMessage(&sQueue, &msg, 0), TRUE); } // Make sure other thread gets a chance to read all messages. OSSleepTicks(OSMillisecondsToTicks(10)); test_eq(sMessagesRead, NumMessages); return 0; }
static ssize_t log_write(struct _reent *r, void *fd, const char *ptr, size_t len) { if (log_socket < 0) return len; while (log_lock) OSSleepTicks(((248625000 / 4)) / 1000); log_lock = 1; int ret; while (len > 0) { int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet ret = send(log_socket, ptr, block, 0); if (ret < 0) break; len -= ret; ptr += ret; } log_lock = 0; return len; }
int __wut_nanosleep(const struct timespec *req, struct timespec *rem) { OSSleepTicks(OSSecondsToTicks(req->tv_sec) + OSNanosecondsToTicks(req->tv_nsec)); rem->tv_sec = 0; rem->tv_nsec = 0; return 0; }
int main(int argc, char **argv) { OSCreateAlarmEx(&sAlarm, "Simple_Alarm"); OSSetAlarm(&sAlarm, OSMilliseconds(50), &AlarmCallback); // Set alarm group and cancel the group OSSetAlarmTag(&sAlarm, 1337); OSCancelAlarms(1337); // Sleep until after alarm was due to go off to test cancellation. OSSleepTicks(OSMilliseconds(100)); return 0; }
int hello_thread() { int last_tm_sec = -1; uint32_t ip = 0; WHBLogPrintf("Hello World from a std::thread!"); if (!nn::ac::GetAssignedAddress(&ip)) { WHBLogPrintf("GetAssignedAddress failed!"); } WHBLogPrintf("My IP is: %u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, (ip >> 0) & 0xFF); while(WHBProcIsRunning()) { OSCalendarTime tm; OSTicksToCalendarTime(OSGetTime(), &tm); if (tm.tm_sec != last_tm_sec) { WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.", tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec); last_tm_sec = tm.tm_sec; } WHBLogConsoleDraw(); OSSleepTicks(OSMillisecondsToTicks(100)); } WHBLogPrintf("Exiting... good bye."); WHBLogConsoleDraw(); OSSleepTicks(OSMillisecondsToTicks(1000)); return 0; }
int main(int argc, char **argv) { WHBProcInit(); WHBLogConsoleInit(); WHBLogPrintf("sCustomHeapAddr = 0x%08X", sCustomHeapAddr); WHBLogPrintf("sCustomHeapSize = 0x%08X", sCustomHeapSize); WHBLogPrintf("MEMGetTotalFreeSizeForExpHeap = 0x%08X", MEMGetTotalFreeSizeForExpHeap(sCustomHeap)); WHBLogPrintf("MEMGetAllocatableSizeForExpHeapEx = 0x%08X", MEMGetAllocatableSizeForExpHeapEx(sCustomHeap, 4)); MEMVisitAllocatedForExpHeap(sCustomHeap, heapBlockVisitor, NULL); while(WHBProcIsRunning()) { WHBLogConsoleDraw(); OSSleepTicks(OSMillisecondsToTicks(100)); } WHBLogConsoleFree(); WHBProcShutdown(); return 0; }
/* This is usually in libogc; we can't use that on wiiu */ int usleep(useconds_t microseconds) { OSSleepTicks(us_to_ticks(microseconds)); return 0; }