Fix syntax errors in C++ mode.
[gnulib.git] / lib / glthread / yield.h
1 /* Yielding the processor to other threads and processes.
2    Copyright (C) 2005-2008 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 # include <synch.h>
77
78 # ifdef __cplusplus
79 extern "C" {
80 # endif
81
82 # define gl_thread_yield() \
83     thr_yield ()
84
85 # ifdef __cplusplus
86 }
87 # endif
88
89 #endif
90
91 /* ========================================================================= */
92
93 #if USE_WIN32_THREADS
94
95 # ifdef __cplusplus
96 extern "C" {
97 # endif
98
99 # define gl_thread_yield() \
100     Sleep (0)
101
102 # ifdef __cplusplus
103 }
104 # endif
105
106 #endif
107
108 /* ========================================================================= */
109
110 #if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS)
111
112 /* Provide dummy implementation if threads are not supported.  */
113
114 # define gl_thread_yield() 0
115
116 #endif
117
118 /* ========================================================================= */
119
120 #endif /* _GLTHREAD_YIELD_H */