1/* Yielding the processor to other threads and processes.
2   Copyright (C) 2005-2010 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 3, 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
36extern "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
57extern "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
78extern "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# include <windows.h>
95
96# ifdef __cplusplus
97extern "C" {
98# endif
99
100# define gl_thread_yield() \
101    Sleep (0)
102
103# ifdef __cplusplus
104}
105# endif
106
107#endif
108
109/* ========================================================================= */
110
111#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS)
112
113/* Provide dummy implementation if threads are not supported.  */
114
115# define gl_thread_yield() 0
116
117#endif
118
119/* ========================================================================= */
120
121#endif /* _GLTHREAD_YIELD_H */
122