Merge "Add clock_settime and clock_nanosleep."

This commit is contained in:
Elliott Hughes 2014-10-14 03:07:42 +00:00 committed by Gerrit Code Review
commit 97df16ba5c
11 changed files with 79 additions and 22 deletions

View File

@ -98,6 +98,7 @@ libc_bionic_src_files := \
bionic/chown.cpp \
bionic/clearenv.cpp \
bionic/clock.cpp \
bionic/clock_nanosleep.cpp \
bionic/clone.cpp \
bionic/__cmsg_nxthdr.cpp \
bionic/connect.cpp \

View File

@ -202,9 +202,9 @@ int swapoff(const char*) all
int settimeofday(const struct timeval*, const struct timezone*) all
clock_t times(struct tms*) all
int nanosleep(const struct timespec*, struct timespec*) all
int clock_settime(clockid_t clk_id, const struct timespec* tp) all
int clock_getres(clockid_t clk_id, struct timespec* res) all
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec* req, struct timespec* rem) all
int clock_settime(clockid_t, const struct timespec*) all
int clock_getres(clockid_t, struct timespec*) all
int __clock_nanosleep:clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*) all
int getitimer(int, const struct itimerval*) all
int setitimer(int, const struct itimerval*, struct itimerval*) all
int __timer_create:timer_create(clockid_t clockid, struct sigevent* evp, __kernel_timer_t* timerid) all

View File

@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
ENTRY(clock_nanosleep)
ENTRY(__clock_nanosleep)
mov ip, r7
ldr r7, =__NR_clock_nanosleep
swi #0
@ -11,4 +11,4 @@ ENTRY(clock_nanosleep)
bxls lr
neg r0, r0
b __set_errno_internal
END(clock_nanosleep)
END(__clock_nanosleep)

View File

@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
ENTRY(clock_nanosleep)
ENTRY(__clock_nanosleep)
mov x8, __NR_clock_nanosleep
svc #0
@ -11,4 +11,5 @@ ENTRY(clock_nanosleep)
b.hi __set_errno_internal
ret
END(clock_nanosleep)
END(__clock_nanosleep)
.hidden __clock_nanosleep

View File

@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
ENTRY(clock_nanosleep)
ENTRY(__clock_nanosleep)
.set noreorder
.cpload t9
li v0, __NR_clock_nanosleep
@ -16,4 +16,4 @@ ENTRY(clock_nanosleep)
j t9
nop
.set reorder
END(clock_nanosleep)
END(__clock_nanosleep)

View File

@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
ENTRY(clock_nanosleep)
ENTRY(__clock_nanosleep)
.set push
.set noreorder
li v0, __NR_clock_nanosleep
@ -22,4 +22,5 @@ ENTRY(clock_nanosleep)
j t9
move ra, t0
.set pop
END(clock_nanosleep)
END(__clock_nanosleep)
.hidden __clock_nanosleep

View File

@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
ENTRY(clock_nanosleep)
ENTRY(__clock_nanosleep)
pushl %ebx
.cfi_def_cfa_offset 8
.cfi_rel_offset ebx, 0
@ -33,4 +33,4 @@ ENTRY(clock_nanosleep)
popl %ecx
popl %ebx
ret
END(clock_nanosleep)
END(__clock_nanosleep)

View File

@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
ENTRY(clock_nanosleep)
ENTRY(__clock_nanosleep)
movq %rcx, %r10
movl $__NR_clock_nanosleep, %eax
syscall
@ -13,4 +13,5 @@ ENTRY(clock_nanosleep)
call __set_errno_internal
1:
ret
END(clock_nanosleep)
END(__clock_nanosleep)
.hidden __clock_nanosleep

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <time.h>
#include "private/ErrnoRestorer.h"
extern "C" int __clock_nanosleep(clockid_t, int, const timespec*, timespec*);
int clock_nanosleep(clockid_t clock_id, int flags, const timespec* in, timespec* out) {
ErrnoRestorer errno_restorer;
return (__clock_nanosleep(clock_id, flags, in, out) == 0) ? 0 : errno;
}

View File

@ -85,8 +85,10 @@ extern void tzset(void) __LIBC_ABI_PUBLIC__;
extern clock_t clock(void) __LIBC_ABI_PUBLIC__;
extern int clock_getres(int, struct timespec*) __LIBC_ABI_PUBLIC__;
extern int clock_gettime(int, struct timespec*) __LIBC_ABI_PUBLIC__;
extern int clock_getres(clockid_t, struct timespec*) __LIBC_ABI_PUBLIC__;
extern int clock_gettime(clockid_t, struct timespec*) __LIBC_ABI_PUBLIC__;
extern int clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*) __LIBC_ABI_PUBLIC__;
extern int clock_settime(clockid_t, const struct timespec*) __LIBC_ABI_PUBLIC__;
extern int timer_create(int, struct sigevent*, timer_t*) __LIBC_ABI_PUBLIC__;
extern int timer_delete(timer_t) __LIBC_ABI_PUBLIC__;

View File

@ -406,9 +406,22 @@ TEST(time, clock_gettime) {
}
TEST(time, clock) {
// clock(3) is hard to test, but a 1s sleep should cost less than 1ms.
clock_t t0 = clock();
sleep(1);
clock_t t1 = clock();
ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000);
// clock(3) is hard to test, but a 1s sleep should cost less than 1ms.
clock_t t0 = clock();
sleep(1);
clock_t t1 = clock();
ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000);
}
TEST(time, clock_settime) {
errno = 0;
timespec ts;
ASSERT_EQ(-1, clock_settime(-1, &ts));
ASSERT_EQ(EINVAL, errno);
}
TEST(time, clock_nanosleep) {
timespec in;
timespec out;
ASSERT_EQ(EINVAL, clock_nanosleep(-1, 0, &in, &out));
}