1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "config.h" 6 7 #include <stddef.h> 8 #include <sys/types.h> 9 #include <sys/time.h> 10 #include <sched.h> 11 #include <unistd.h> 12 13 #ifdef HAVE_SYS_SELECT_H 14 #include <sys/select.h> 15 #endif 16 17 #include "runtime.h" 18 19 /* Spin wait. */ 20 21 void runtime_procyield(uint32 cnt)22runtime_procyield (uint32 cnt) 23 { 24 volatile uint32 i; 25 26 for (i = 0; i < cnt; ++i) 27 { 28 #if defined (__i386__) || defined (__x86_64__) 29 __builtin_ia32_pause (); 30 #endif 31 } 32 } 33 34 /* Ask the OS to reschedule this thread. */ 35 36 void runtime_osyield(void)37runtime_osyield (void) 38 { 39 sched_yield (); 40 } 41 42 /* Sleep for some number of microseconds. */ 43 44 void runtime_usleep(uint32 us)45runtime_usleep (uint32 us) 46 { 47 struct timeval tv; 48 49 tv.tv_sec = us / 1000000; 50 tv.tv_usec = us % 1000000; 51 select (0, NULL, NULL, NULL, &tv); 52 } 53