diff options
author | Bruno Haible <bruno@clisp.org> | 2019-07-15 02:36:10 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-07-15 02:36:10 +0200 |
commit | 3fdb19cf7a5c3c4ada691fdb9d8e01701c747298 (patch) | |
tree | 02fc733152bbbaa921b137ee341868562c9fc84c /lib/sched_yield.c | |
parent | f76440c5c82def5a6e7541b224d9a5b794b689a1 (diff) | |
download | gnulib-3fdb19cf7a5c3c4ada691fdb9d8e01701c747298.tar.gz |
sched_yield: New module.
* lib/sched.in.h: Add _GL_FUNCDECL_RPL, _GL_WARN_ON_USE placeholders.
(sched_yield): New declaration.
* lib/sched_yield.c: New file.
* m4/sched_yield.m4: New file.
* m4/sched_h.m4 (gl_SCHED_H): Require gl_SCHED_H_DEFAULTS. Arrange to
provide a replacement sched.h always. Test whether sched_yield is
declared.
(gl_SCHED_MODULE_INDICATOR, gl_SCHED_H_DEFAULTS): New macros.
* modules/sched (Depends-on): Add snippet/c++defs, snippet/warn-on-use.
(Makefile.am): Provide a replacement sched.h always. Substitute
GNULIB_SCHED_YIELD, HAVE_SCHED_YIELD, REPLACE_SCHED_YIELD,
_GL_FUNCDECL_RPL, _GL_WARN_ON_USE.
* modules/sched_yield: New file.
* doc/posix-functions/sched_yield.texi: Mention the new module.
Diffstat (limited to 'lib/sched_yield.c')
-rw-r--r-- | lib/sched_yield.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/sched_yield.c b/lib/sched_yield.c new file mode 100644 index 0000000000..57490d141c --- /dev/null +++ b/lib/sched_yield.c @@ -0,0 +1,46 @@ +/* Schedule other threads to run. + Copyright (C) 2019 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2019. */ + +#include <config.h> + +/* Specification. */ +#include <sched.h> + +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +/* Use Windows threads. */ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include <windows.h> + +int +sched_yield (void) +{ + Sleep (0); + return 0; +} + +#else +/* Provide a dummy implementation for single-threaded applications. */ + +int +sched_yield (void) +{ + return 0; +} + +#endif |