New module 'yield'.
authorBruno Haible <bruno@clisp.org>
Sun, 17 Aug 2008 19:02:11 +0000 (21:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 17 Aug 2008 19:02:11 +0000 (21:02 +0200)
ChangeLog
MODULES.html.sh
lib/glthread/yield.h [new file with mode: 0644]
m4/yield.m4 [new file with mode: 0644]
modules/yield [new file with mode: 0644]

index 3379f32..7cf29c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 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'.
        * modules/thread: New file.
        * lib/glthread/thread.h: New file.
index c304b33..43dad36 100755 (executable)
@@ -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 (file)
index 0000000..80cfb88
--- /dev/null
@@ -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 */
diff --git a/m4/yield.m4 b/m4/yield.m4
new file mode 100644 (file)
index 0000000..8701a86
--- /dev/null
@@ -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 (file)
index 0000000..6eb7580
--- /dev/null
@@ -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
+