PR c++/63283
[official-gcc.git] / libgo / runtime / yield.c
blob442d346db7d87628c8390c74e589fbd2cf5740bf
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 #if defined (__i386__) || defined (__x86_64__)
18 #include <xmmintrin.h>
19 #endif
21 #include "runtime.h"
23 /* Spin wait. */
25 void
26 runtime_procyield (uint32 cnt)
28 volatile uint32 i;
30 for (i = 0; i < cnt; ++i)
32 #if defined (__i386__) || defined (__x86_64__)
33 _mm_pause ();
34 #endif
38 /* Ask the OS to reschedule this thread. */
40 void
41 runtime_osyield (void)
43 sched_yield ();
46 /* Sleep for some number of microseconds. */
48 void
49 runtime_usleep (uint32 us)
51 struct timeval tv;
53 tv.tv_sec = us / 1000000;
54 tv.tv_usec = us % 1000000;
55 select (0, NULL, NULL, NULL, &tv);