Add sched_yield(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-09-16 21:16:35 +02:00
parent af23f7ad5e
commit f332cf96d4
5 changed files with 79 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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 \

36
libc/include/sched.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
sched.h
Executing scheduling.
*******************************************************************************/
#ifndef INCLUDE_SCHED_H
#define INCLUDE_SCHED_H
#include <sys/cdefs.h>
__BEGIN_DECLS
int sched_yield(void);
__END_DECLS
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
sched/sched_yield.cpp
Yields control of the CPU so another thread can run.
*******************************************************************************/
#include <sys/syscall.h>
#include <sched.h>
DEFN_SYSCALL0(int, sys_sched_yield, SYSCALL_SCHED_YIELD);
extern "C" int sched_yield(void)
{
return sys_sched_yield();
}