Merge branch 'stable'
[gnulib.git] / lib / glthread / yield.h
1 /* Yielding the processor to other threads and processes.
2    Copyright (C) 2005-2011 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* This file contains a primitive for yielding the processor to other threads.
19      extern void gl_thread_yield (void);
20  */
21
22 #ifndef _GLTHREAD_YIELD_H
23 #define _GLTHREAD_YIELD_H
24
25 #include <errno.h>
26
27 /* ========================================================================= */
28
29 #if USE_POSIX_THREADS
30
31 /* Use the POSIX threads library.  */
32
33 # include <sched.h>
34
35 # ifdef __cplusplus
36 extern "C" {
37 # endif
38
39 # define gl_thread_yield() \
40     sched_yield ()
41
42 # ifdef __cplusplus
43 }
44 # endif
45
46 #endif
47
48 /* ========================================================================= */
49
50 #if USE_PTH_THREADS
51
52 /* Use the GNU Pth threads library.  */
53
54 # include <pth.h>
55
56 # ifdef __cplusplus
57 extern "C" {
58 # endif
59
60 # define gl_thread_yield() \
61     pth_yield (NULL)
62
63 # ifdef __cplusplus
64 }
65 # endif
66
67 #endif
68
69 /* ========================================================================= */
70
71 #if USE_SOLARIS_THREADS
72
73 /* Use the old Solaris threads library.  */
74
75 # include <thread.h>
76
77 # ifdef __cplusplus
78 extern "C" {
79 # endif
80
81 # define gl_thread_yield() \
82     thr_yield ()
83
84 # ifdef __cplusplus
85 }
86 # endif
87
88 #endif
89
90 /* ========================================================================= */
91
92 #if USE_WIN32_THREADS
93
94 # define WIN32_LEAN_AND_MEAN  /* avoid including junk */
95 # include <windows.h>
96
97 # ifdef __cplusplus
98 extern "C" {
99 # endif
100
101 # define gl_thread_yield() \
102     Sleep (0)
103
104 # ifdef __cplusplus
105 }
106 # endif
107
108 #endif
109
110 /* ========================================================================= */
111
112 #if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS)
113
114 /* Provide dummy implementation if threads are not supported.  */
115
116 # define gl_thread_yield() 0
117
118 #endif
119
120 /* ========================================================================= */
121
122 #endif /* _GLTHREAD_YIELD_H */