summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2010-05-19 08:32:16 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-05-19 08:32:16 +0200
commitd4d74c5f56d312885acf59ce0981994eef8e3dba (patch)
treeb9ad80ef6233dc8f5b4a8f19c3fd47cf819ab980
parentfb30b6bbf28d91667dcb9691dfeefffac4f99b82 (diff)
Add pthread_yield function
* pthread/pt-yield.c: New file. * Makefile (SRCS): Add pt-yield.c * Makefile.am (libpthread_a_SOURCES): Add pt-yield.c
-rw-r--r--Makefile1
-rw-r--r--Makefile.am1
-rw-r--r--include/pthread/pthread.h10
-rw-r--r--pthread/pt-yield.c26
4 files changed, 37 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 04dfb26..2b895e8 100644
--- a/Makefile
+++ b/Makefile
@@ -122,6 +122,7 @@ SRCS := pt-attr.c pt-attr-destroy.c pt-attr-getdetachstate.c \
pt-getcpuclockid.c \
\
pt-getschedparam.c pt-setschedparam.c pt-setschedprio.c \
+ pt-yield.c \
\
sem-close.c sem-destroy.c sem-getvalue.c sem-init.c sem-open.c \
sem-post.c sem-timedwait.c sem-trywait.c sem-unlink.c \
diff --git a/Makefile.am b/Makefile.am
index e59c946..e1c062c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -133,6 +133,7 @@ libpthread_a_SOURCES = pt-attr.c pt-attr-destroy.c pt-attr-getdetachstate.c \
pt-kill.c \
pt-getcpuclockid.c \
pt-getschedparam.c pt-setschedparam.c pt-setschedprio.c \
+ pt-yield.c \
sem-close.c sem-init.c sem-timedwait.c sem-wait.c \
sem-destroy.c sem-open.c sem-trywait.c sem-getvalue.c \
sem-post.c sem-unlink.c \
diff --git a/include/pthread/pthread.h b/include/pthread/pthread.h
index fbe3294..e6b9249 100644
--- a/include/pthread/pthread.h
+++ b/include/pthread/pthread.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002, 2005, 2006, 2007, 2008, 2009
+/* Copyright (C) 2000, 2002, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -734,6 +734,14 @@ extern int pthread_setschedparam (pthread_t thread, int policy,
/* Set thread THREAD's scheduling priority. */
extern int pthread_setschedprio (pthread_t thread, int prio);
+
+#ifdef __USE_GNU
+/* Yield the processor to another thread or process.
+ This function is similar to the POSIX `sched_yield' function but
+ might be differently implemented in the case of a m-on-n thread
+ implementation. */
+extern int pthread_yield (void);
+#endif
/* Kernel-specific interfaces. */
diff --git a/pthread/pt-yield.c b/pthread/pt-yield.c
new file mode 100644
index 0000000..27848bb
--- /dev/null
+++ b/pthread/pt-yield.c
@@ -0,0 +1,26 @@
+/* Yield the processor to another thread or process.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <sched.h>
+
+int pthread_yield(void)
+{
+ return sched_yield ();
+}