[libc-commits] [PATCH] D147985: [LIBC] Implement `sched_yield()`
Noah Goldstein via Phabricator via libc-commits
libc-commits at lists.llvm.org
Mon Apr 10 18:07:28 PDT 2023
goldstein.w.n created this revision.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
goldstein.w.n requested review of this revision.
Implements: https://linux.die.net/man/2/sched_yield
Possibly we don't need the return value check / errno as according to
both the manpage (and current linux source) `sched_yield` cannot fail.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147985
Files:
libc/src/sched/linux/CMakeLists.txt
libc/src/sched/linux/sched_yield.cpp
libc/src/sched/sched_yield.h
Index: libc/src/sched/sched_yield.h
===================================================================
--- /dev/null
+++ libc/src/sched/sched_yield.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for sched_yield -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SCHED_SCHED_YIELD_H
+#define LLVM_LIBC_SRC_SCHED_SCHED_YIELD_H
+
+namespace __llvm_libc {
+
+int sched_yield(void);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SCHED_SCHED_YIELD_H
Index: libc/src/sched/linux/sched_yield.cpp
===================================================================
--- /dev/null
+++ libc/src/sched/linux/sched_yield.cpp
@@ -0,0 +1,28 @@
+//===-- Implementation of sched_yield -------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sched/sched_yield.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, sched_yield, ()) {
+ long ret = __llvm_libc::syscall_impl(SYS_sched_yield);
+ // As of writing this, yield() cannot fail
+ if (ret < 0) {
+ libc_errno = -ret;
+ return -1;
+ }
+ return 0;
+}
+
+} // namespace __llvm_libc
Index: libc/src/sched/linux/CMakeLists.txt
===================================================================
--- libc/src/sched/linux/CMakeLists.txt
+++ libc/src/sched/linux/CMakeLists.txt
@@ -30,4 +30,16 @@
../sched_getcpucount.h
DEPENDS
libc.include.sched
+ )
+
+add_entrypoint_object(
+ sched_yield
+ SRCS
+ sched_yield.cpp
+ HDRS
+ ../sched_yield.h
+ DEPENDS
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147985.512298.patch
Type: text/x-patch
Size: 2298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230411/d8804b49/attachment.bin>
More information about the libc-commits
mailing list