[libcxx-commits] [PATCH] D99373: [SystemZ][z/OS] tune down warning about unused parameter on nanosleep()
Zibi Sarbino via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 26 09:02:05 PDT 2021
zibi updated this revision to Diff 333566.
zibi added a comment.
Fix issues with rc and errno as well adding cast for conversion warrnings.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99373/new/
https://reviews.llvm.org/D99373
Files:
libcxx/include/__support/ibm/nanosleep.h
Index: libcxx/include/__support/ibm/nanosleep.h
===================================================================
--- libcxx/include/__support/ibm/nanosleep.h
+++ libcxx/include/__support/ibm/nanosleep.h
@@ -12,24 +12,41 @@
#include <unistd.h>
-inline int nanosleep(const struct timespec*, struct timespec* rem) {
+inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
// The nanosleep() function is not available on z/OS. Therefore, we will call
// sleep() to sleep for whole seconds and usleep() to sleep for any remaining
// fraction of a second. Any remaining nanoseconds will round up to the next
// microsecond.
-
- useconds_t __micro_sec = (rem->tv_nsec + 999) / 1000;
+ if (__req->tv_sec < 0 || __req->tv_nsec < 0 || __req->tv_nsec > 999999999) {
+ errno = EINVAL;
+ return -1;
+ }
+ useconds_t __micro_sec =
+ static_cast<useconds_t>((__req->tv_nsec + 999) / 1000);
+ time_t __sec = __req->tv_sec;
if (__micro_sec > 999999) {
- ++rem->tv_sec;
+ ++__sec;
__micro_sec -= 1000000;
}
- while (rem->tv_sec)
- rem->tv_sec = sleep(rem->tv_sec);
+ __sec = sleep(static_cast<unsigned int>(__sec));
+ if (__sec) {
+ if (__rem) {
+ __rem->tv_sec = __sec;
+ __rem->tv_nsec = __micro_sec * 1000;
+ }
+ errno = EINTR;
+ return -1;
+ }
if (__micro_sec) {
- rem->tv_nsec = __micro_sec * 1000;
- return usleep(__micro_sec);
+ int rc = usleep(__micro_sec);
+ if (rc != 0 && __rem) {
+ __rem->tv_sec = 0;
+ __rem->tv_nsec = __micro_sec * 1000;
+ // errno is already set
+ return -1;
+ }
+ return rc;
}
- rem->tv_nsec = 0;
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99373.333566.patch
Type: text/x-patch
Size: 1679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210326/66dbae38/attachment.bin>
More information about the libcxx-commits
mailing list