From 5141c54dc384f9bdf4cf4561f603f2ddf13eebd8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 17 Aug 2008 21:02:11 +0200 Subject: [PATCH] New module 'yield'. --- ChangeLog | 8 ++++ MODULES.html.sh | 1 + lib/glthread/yield.h | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++ m4/yield.m4 | 19 ++++++++++ modules/yield | 29 ++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 lib/glthread/yield.h create mode 100644 m4/yield.m4 create mode 100644 modules/yield diff --git a/ChangeLog b/ChangeLog index 3379f3208..7cf29c2c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2008-08-17 Yoann Vandoorselaere + New module 'yield'. + * modules/yield: New file. + * lib/glthread/yield.h: New file. + * m4/yield.m4: New file. + * MODULES.html.sh (Multithreading): Add yield. + +2008-08-17 Yoann Vandoorselaere + New module 'thread'. * modules/thread: New file. * lib/glthread/thread.h: New file. diff --git a/MODULES.html.sh b/MODULES.html.sh index c304b33e0..43dad362c 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2380,6 +2380,7 @@ func_all_modules () func_module lock func_module tls func_module thread + func_module yield func_module cond func_module openmp func_end_table diff --git a/lib/glthread/yield.h b/lib/glthread/yield.h new file mode 100644 index 000000000..80cfb888a --- /dev/null +++ b/lib/glthread/yield.h @@ -0,0 +1,104 @@ +/* Yielding the processor to other threads and processes. + Copyright (C) 2005-2008 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* This file contains a primitive for yielding the processor to other threads. + extern void gl_thread_yield (void); + */ + +#ifndef _GLTHREAD_YIELD_H +#define _GLTHREAD_YIELD_H + +#include + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# define gl_thread_yield() \ + sched_yield () + +#endif + +/* ========================================================================= */ + +#if USE_PTH_THREADS + +/* Use the GNU Pth threads library. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# define gl_thread_yield() \ + pth_yield (NULL) + +#endif + +/* ========================================================================= */ + +#if USE_SOLARIS_THREADS + +/* Use the old Solaris threads library. */ + +# include +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# define gl_thread_yield() \ + thr_yield () + +#endif + +/* ========================================================================= */ + +#if USE_WIN32_THREADS + +# ifdef __cplusplus +extern "C" { +# endif + +# define gl_thread_yield() \ + Sleep (0) + +#endif + +/* ========================================================================= */ + +#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS) + +/* Provide dummy implementation if threads are not supported. */ + +# define gl_thread_yield() 0 + +#endif + +/* ========================================================================= */ + +#endif /* _GLTHREAD_YIELD_H */ diff --git a/m4/yield.m4 b/m4/yield.m4 new file mode 100644 index 000000000..8701a8670 --- /dev/null +++ b/m4/yield.m4 @@ -0,0 +1,19 @@ +# yield.m4 serial 1 +dnl Copyright (C) 2005-2008 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_YIELD], +[ + AC_REQUIRE([gl_THREADLIB]) + dnl On some systems, sched_yield is in librt, rather than in libpthread. + YIELD_LIB= + if test $gl_threads_api = posix; then + dnl Solaris has sched_yield in librt, not in libpthread or libc. + AC_CHECK_LIB(rt, sched_yield, [YIELD_LIB=-lrt], + [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt. + AC_CHECK_LIB(posix4, sched_yield, [YIELD_LIB=-lposix4])]) + fi + AC_SUBST([YIELD_LIB]) +]) diff --git a/modules/yield b/modules/yield new file mode 100644 index 000000000..6eb7580e8 --- /dev/null +++ b/modules/yield @@ -0,0 +1,29 @@ +Description: +Yielding the processor to other threads. + +Files: +lib/glthread/yield.h +m4/yield.m4 + +Depends-on: +threadlib + +configure.ac: +gl_YIELD + +Makefile.am: +lib_SOURCES += glthread/yield.h + +Include: +"glthread/yield.h" + +Link: +$(LTLIBTHREAD) when linking with libtool, $(LIBTHREAD) otherwise +$(YIELD_LIB) + +License: +LGPLv2+ + +Maintainer: +Yoann Vandoorselaere + -- 2.11.0