changeset 10329:b4b925d625c0

New module 'yield'.
author Bruno Haible <bruno@clisp.org>
date Sun, 17 Aug 2008 21:02:11 +0200
parents 23382c738abc
children f4a133133dce
files ChangeLog MODULES.html.sh lib/glthread/yield.h m4/yield.m4 modules/yield
diffstat 5 files changed, 161 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-08-17  Yoann Vandoorselaere  <yoann.v@prelude-ids.com>
+
+	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  <yoann.v@prelude-ids.com>
 
 	New module 'thread'.
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2380,6 +2380,7 @@
   func_module lock
   func_module tls
   func_module thread
+  func_module yield
   func_module cond
   func_module openmp
   func_end_table
new file mode 100644
--- /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 <errno.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <sched.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    sched_yield ()
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    pth_yield (NULL)
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+# include <synch.h>
+
+# 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 */
new file mode 100644
--- /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])
+])
new file mode 100644
--- /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
+