Revert "fix" for PR bootstrap/51072
[official-gcc.git] / libgo / runtime / yield.c
blob4c2204d35380d46998306e389c052712f8873d46
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 #define _GNU_SOURCE
7 #include "config.h"
9 #include <stddef.h>
10 #include <sys/types.h>
11 #include <sys/time.h>
12 #include <sched.h>
13 #include <unistd.h>
15 #ifdef HAVE_SYS_SELECT_H
16 #include <sys/select.h>
17 #endif
19 #include "runtime.h"
21 /* Spin wait. */
23 void
24 runtime_procyield (uint32 cnt)
26 volatile uint32 i;
28 for (i = 0; i < cnt; ++i)
30 #if defined (__i386__) || defined (__x86_64__)
31 __builtin_ia32_pause ();
32 #endif
36 /* Ask the OS to reschedule this thread. */
38 void
39 runtime_osyield (void)
41 sched_yield ();
44 /* Sleep for some number of microseconds. */
46 void
47 runtime_usleep (uint32 us)
49 struct timeval tv;
51 tv.tv_sec = us / 1000000;
52 tv.tv_usec = us % 1000000;
53 select (0, NULL, NULL, NULL, &tv);