mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Introduce clock_nanosleep()
This commit is contained in:
parent
fe3216e961
commit
b75a4654cf
33 changed files with 553 additions and 100 deletions
|
@ -50,6 +50,7 @@ const char *DescribeRemapFlags(char[48], int);
|
|||
const char *DescribeRlimitName(char[20], int);
|
||||
const char *DescribeSchedPolicy(char[48], int);
|
||||
const char *DescribeSeccompOperation(int);
|
||||
const char *DescribeSleepFlags(char[16], int);
|
||||
const char *DescribeSockLevel(char[12], int);
|
||||
const char *DescribeSockOptname(char[32], int, int);
|
||||
const char *DescribeSocketFamily(char[12], int);
|
||||
|
@ -92,6 +93,7 @@ const char *DescribeWhence(char[12], int);
|
|||
#define DescribeRemapFlags(x) DescribeRemapFlags(alloca(48), x)
|
||||
#define DescribeRlimitName(rl) DescribeRlimitName(alloca(20), rl)
|
||||
#define DescribeSchedPolicy(x) DescribeSchedPolicy(alloca(48), x)
|
||||
#define DescribeSleepFlags(x) DescribeSleepFlags(alloca(16), x)
|
||||
#define DescribeSockLevel(x) DescribeSockLevel(alloca(12), x)
|
||||
#define DescribeSockOptname(x, y) DescribeSockOptname(alloca(32), x, y)
|
||||
#define DescribeSocketFamily(x) DescribeSocketFamily(alloca(12), x)
|
||||
|
|
|
@ -16,30 +16,22 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
||||
// we don't want instrumentation because:
|
||||
// - nanosleep() depends on this and ftrace can take microsecs
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/sysv/consts/timer.h"
|
||||
|
||||
/**
|
||||
* Converts `struct timespec` to `struct timeval`.
|
||||
*
|
||||
* This divides ts.tv_nsec by 1000 with upward rounding and overflow
|
||||
* handling. Your ts.tv_nsec must be on the interval `[0,1000000000)`
|
||||
* otherwise `{-1, -1}` is returned.
|
||||
*
|
||||
* @return converted timeval whose tv_usec will be -1 on error
|
||||
* Describes clock_nanosleep() flags argument.
|
||||
*/
|
||||
noinstrument struct timeval _timespec2timeval(struct timespec ts) {
|
||||
if (0 <= ts.tv_nsec && ts.tv_nsec < 1000000000) {
|
||||
if (0 <= ts.tv_nsec && ts.tv_nsec < 1000000000 - 999) {
|
||||
return (struct timeval){ts.tv_sec, (ts.tv_nsec + 999) / 1000};
|
||||
} else {
|
||||
return (struct timeval){ts.tv_sec + 1, 0};
|
||||
}
|
||||
} else {
|
||||
return (struct timeval){-1, -1};
|
||||
const char *(DescribeSleepFlags)(char buf[16], int x) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
return "0";
|
||||
case TIMER_ABSTIME:
|
||||
return "TIMER_ABSTIME";
|
||||
default:
|
||||
FormatInt32(buf, x);
|
||||
return buf;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue