libs/libc/time: add gethrtime() support
Change-Id: I8882207d3a7e5062f70c7b4b95205361c71f8744 Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
b3541ccaf8
commit
c38c821fc2
@ -44,6 +44,7 @@
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -138,6 +139,8 @@
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
typedef clock_t hrtime_t;
|
||||
|
||||
/* struct timeval represents time as seconds plus microseconds */
|
||||
|
||||
struct timeval
|
||||
@ -383,6 +386,19 @@ int setitimer(int which, FAR const struct itimerval *value,
|
||||
|
||||
int utimes(FAR const char *path, const struct timeval times[2]);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gethrtime
|
||||
*
|
||||
* Description:
|
||||
* Get the current time
|
||||
*
|
||||
* Returned Value:
|
||||
* The current value of the system time in ns
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
hrtime_t gethrtime(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ CSRCS += lib_strftime.c lib_calendar2utc.c lib_daysbeforemonth.c
|
||||
CSRCS += lib_gettimeofday.c lib_isleapyear.c lib_settimeofday.c lib_time.c
|
||||
CSRCS += lib_timespec_get.c lib_nanosleep.c lib_difftime.c lib_dayofweek.c
|
||||
CSRCS += lib_asctime.c lib_asctimer.c lib_ctime.c lib_ctimer.c
|
||||
CSRCS += lib_gethrtime.c
|
||||
|
||||
ifdef CONFIG_LIBC_LOCALTIME
|
||||
CSRCS += lib_localtime.c
|
||||
|
56
libs/libc/time/lib_gethrtime.c
Normal file
56
libs/libc/time/lib_gethrtime.c
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/time/lib_gethrtime.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gethrtime
|
||||
*
|
||||
* Description:
|
||||
* Get the current time
|
||||
*
|
||||
* Returned Value:
|
||||
* The current value of the system time in ns
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
hrtime_t gethrtime(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
#ifdef CONFIG_CLOCK_MONOTONIC
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
#endif
|
||||
|
||||
return (hrtime_t)1000000000 * ts.tv_sec + ts.tv_nsec;
|
||||
}
|
Loading…
Reference in New Issue
Block a user