* const-uniq-1.c: Expand regex to match AIX XCOFF labels.
[official-gcc.git] / libgo / runtime / yield.c
blob5c47719d48f76e78c8b5048e61648d366886de5b
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.
5 #include "config.h"
7 #include <stddef.h>
8 #include <sys/types.h>
9 #include <sys/time.h>
10 #include <sched.h>
11 #include <unistd.h>
13 #ifdef HAVE_SYS_SELECT_H
14 #include <sys/select.h>
15 #endif
17 #include "runtime.h"
19 /* Spin wait. */
21 void
22 runtime_procyield (uint32 cnt)
24 volatile uint32 i;
26 for (i = 0; i < cnt; ++i)
28 #if defined (__i386__) || defined (__x86_64__)
29 __builtin_ia32_pause ();
30 #endif
34 /* Ask the OS to reschedule this thread. */
36 void
37 runtime_osyield (void)
39 sched_yield ();
42 /* Sleep for some number of microseconds. */
44 void
45 runtime_usleep (uint32 us)
47 struct timeval tv;
49 tv.tv_sec = us / 1000000;
50 tv.tv_usec = us % 1000000;
51 select (0, NULL, NULL, NULL, &tv);