diff --git a/kernel/include/sortix/syscallnum.h b/kernel/include/sortix/syscallnum.h
index a1720bd7..c182a1cc 100644
--- a/kernel/include/sortix/syscallnum.h
+++ b/kernel/include/sortix/syscallnum.h
@@ -152,6 +152,7 @@
#define SYSCALL_FSTATVFSAT 128
#define SYSCALL_RDMSR 129
#define SYSCALL_WRMSR 130
-#define SYSCALL_MAX_NUM 131 /* index of highest constant + 1 */
+#define SYSCALL_SCHED_YIELD 131
+#define SYSCALL_MAX_NUM 132 /* index of highest constant + 1 */
#endif
diff --git a/kernel/scheduler.cpp b/kernel/scheduler.cpp
index 1d73a2dc..7b6d6df1 100644
--- a/kernel/scheduler.cpp
+++ b/kernel/scheduler.cpp
@@ -311,6 +311,11 @@ static int sys_usleep(size_t usecs)
return 0;
}
+static int sys_sched_yield(void)
+{
+ return kthread_yield(), 0;
+}
+
void Init()
{
premagic = postmagic = SCHED_MAGIC;
@@ -329,6 +334,7 @@ void Init()
Syscall::Register(SYSCALL_SLEEP, (void*) sys_sleep);
Syscall::Register(SYSCALL_USLEEP, (void*) sys_usleep);
+ Syscall::Register(SYSCALL_SCHED_YIELD, (void*) sys_sched_yield);
}
} // namespace Scheduler
diff --git a/libc/Makefile b/libc/Makefile
index 8ecf0c18..323cb714 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -339,6 +339,7 @@ pwd/getpwuid.o \
pwd/getpwuid_r.o \
pwd/openpw.o \
pwd/setpwent.o \
+sched/sched_yield.o \
signal/kill.o \
signal/killpg.o \
signal/psignal.o \
diff --git a/libc/include/sched.h b/libc/include/sched.h
new file mode 100644
index 00000000..f969976c
--- /dev/null
+++ b/libc/include/sched.h
@@ -0,0 +1,36 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ sched.h
+ Executing scheduling.
+
+*******************************************************************************/
+
+#ifndef INCLUDE_SCHED_H
+#define INCLUDE_SCHED_H
+
+#include
+
+__BEGIN_DECLS
+
+int sched_yield(void);
+
+__END_DECLS
+
+#endif
diff --git a/libc/sched/sched_yield.cpp b/libc/sched/sched_yield.cpp
new file mode 100644
index 00000000..664d87a1
--- /dev/null
+++ b/libc/sched/sched_yield.cpp
@@ -0,0 +1,34 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ sched/sched_yield.cpp
+ Yields control of the CPU so another thread can run.
+
+*******************************************************************************/
+
+#include
+
+#include
+
+DEFN_SYSCALL0(int, sys_sched_yield, SYSCALL_SCHED_YIELD);
+
+extern "C" int sched_yield(void)
+{
+ return sys_sched_yield();
+}