void MicroSleep( uint32 microsec ) { #ifdef ist_env_Windows if(microsec==0) { return; } Timer timer; while(uint32(timer.getElapsedMicrosec())<microsec) { YieldCPU(); } #else // ist_env_Windows return ::usleep(microsec); #endif // ist_env_Windows }
void NanoSleep( uint32 nanosec ) { #ifdef ist_env_Windows if(nanosec==0) { return; } Timer timer; while(uint32(timer.getElapsedNanosec())<nanosec) { YieldCPU(); } #else // ist_env_Windows timespec ts = {0, nanosec}; return ::nanosleep(&ts); #endif // ist_env_Windows }
void TCPAckMonitor(TCPConnection* tcp) { uint64_t ppt = tcp->lastpackettime; // uint8_t* buf = new uint8_t[GLOBAL_MTU]; while(true) { while(tcp->lastpackettime == 0 || ppt == tcp->lastpackettime || Time::Now() < tcp->lastpackettime + TCP_TIMEOUT) YieldCPU(); ppt = tcp->lastpackettime; tcp->AlreadyAcked = true; // flush tcp to application. tcp->SendPacket(0, 0, 0x10); } }
void yield_test() { int i = 0; int j = 0; while(1) { if (i % 100000000 == 0) { int id = GetMyId(); printf("yield_test tid: %d j = %d\n", id, j); j++; } if (j % 5 == 0) { j++; printf("YIELDING CPU tid: %d\n", GetMyId()); YieldCPU(); } i++; } }
void testcase5_f(void) { int i = 0; printf("%s: id=%d: Yielding CPU when i > 10000000\n", __FUNCTION__, GetMyId()); while (1) { i++; if (i > 10000000) { YieldCPU(); } if (i % 10000000 == 0) { // don't create tcb on stack. Stack size is too small ut_tcb_t *tcb = malloc(sizeof(ut_tcb_t)); printf("%s: id=%d: Getting status of current thread. Return value = %d\n", __FUNCTION__, GetMyId(), GetStatus(GetMyId(), tcb)); ut_tcb_print_info(tcb, true); } } }