mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 20:44:39 +08:00
libc/time: Add an implementationof clock()
This commit is contained in:
+5
-1
@@ -231,9 +231,13 @@ typedef int16_t blksize_t;
|
||||
typedef unsigned int socklen_t;
|
||||
typedef uint16_t sa_family_t;
|
||||
|
||||
/* Used for system times in clock ticks */
|
||||
/* Used for system times in clock ticks (equivalent to systime_t) */
|
||||
|
||||
#ifdef CONFIG_SYSTEM_TIME64
|
||||
typedef uint64_t clock_t;
|
||||
#else
|
||||
typedef uint32_t clock_t;
|
||||
#endif
|
||||
|
||||
/* The type useconds_t shall be an unsigned integer type capable of storing
|
||||
* values at least in the range [0, 1000000]. The type suseconds_t shall be
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
############################################################################
|
||||
# libc/time/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011-2012, 2014-2015, 2018 Gregory Nutt. All rights
|
||||
# reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,7 +38,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_difftime.c
|
||||
CSRCS += lib_difftime.c lib_clock.c
|
||||
|
||||
ifndef CONFIG_DISABLE_SIGNALS
|
||||
CSRCS += lib_nanosleep.c
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
* string representation. asctime is not re-entrant; asctime_r is re-
|
||||
* entrant
|
||||
*
|
||||
* Parameters:
|
||||
* Input Parameters:
|
||||
* tp - Pointer to the time to be converted.
|
||||
*
|
||||
* Returned Value:
|
||||
|
||||
@@ -74,7 +74,7 @@ static const char * const g_mon_name[12] =
|
||||
* string representation. asctime is not re-entrant; asctime_r is re-
|
||||
* entrant.
|
||||
*
|
||||
* Parameters:
|
||||
* Input Parameters:
|
||||
* tp - Pointer to the time to be converted.
|
||||
* buf - A user provided buffer to receive the 26 character time string.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
* libc/time/lib_clock.c
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <nuttx/clock.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: clock
|
||||
*
|
||||
* Description:
|
||||
* The clock() function returns the implementation's best approximation to
|
||||
* the processor time used by the process since the beginning of a
|
||||
* implementation-defined era related only to the process invocation.
|
||||
*
|
||||
* To determine the time in seconds, the value returned by clock() should
|
||||
* be divided by the value of the macro CLOCKS_PER_SEC as defined in <time.h>.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* The system time in units of clock ticks is returend. If the processor
|
||||
* time used is not available or its value cannot be represented, the
|
||||
* function will return the value (clock_t)-1.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
clock_t clock(void)
|
||||
{
|
||||
return (clock_t)clock_systimer();
|
||||
}
|
||||
@@ -55,7 +55,7 @@
|
||||
* epoch to a string representation. ctime is not re-entrant; ctime_r is
|
||||
* re-entrant.
|
||||
*
|
||||
* Parameters:
|
||||
* Input Parameters:
|
||||
* timep - The current time represented as seconds since the epoch.
|
||||
*
|
||||
* Returned Value:
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
* epoch to a string representation. ctime is not re-entrant; ctime_r is
|
||||
* re-entrant.
|
||||
*
|
||||
* Parameters:
|
||||
* Input Parameters:
|
||||
* timep - The current time represented as seconds since the epoch.
|
||||
* buf - A user provided buffer to receive the 26 character time string.
|
||||
*
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
* The use of the nanosleep() function has no effect on the action or
|
||||
* blockage of any signal.
|
||||
*
|
||||
* Parameters:
|
||||
* Input Parameters:
|
||||
* rqtp - The amount of time to be suspended from execution.
|
||||
* rmtp - If the rmtp argument is non-NULL, the timespec structure
|
||||
* referenced by it is updated to contain the amount of time
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
* and is provided for compatibility. clock_gettime() is the preferred way
|
||||
* to obtain system time.
|
||||
*
|
||||
* Parameters:
|
||||
* Input Parameters:
|
||||
* Pointer to an object of type time_t, where the time value is stored.
|
||||
* Alternatively, this parameter can be a null pointer, in which case the
|
||||
* parameter is not used, but a time_t object is still returned by the
|
||||
|
||||
@@ -136,15 +136,15 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
* is outside of the scope of getsockopt.
|
||||
*/
|
||||
|
||||
case SO_DEBUG: /* Enables recording of debugging information */
|
||||
case SO_BROADCAST: /* Permits sending of broadcast messages */
|
||||
case SO_REUSEADDR: /* Allow reuse of local addresses */
|
||||
case SO_DEBUG: /* Enables recording of debugging information */
|
||||
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
||||
#ifndef CONFIG_NET_TCPPROTO_OPTIONS
|
||||
case SO_KEEPALIVE: /* Verifies TCP connections active by enabling the
|
||||
* periodic transmission of probes */
|
||||
#endif
|
||||
case SO_OOBINLINE: /* Leaves received out-of-band data inline */
|
||||
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
||||
case SO_REUSEADDR: /* Allow reuse of local addresses */
|
||||
{
|
||||
sockopt_t optionset;
|
||||
|
||||
@@ -254,14 +254,14 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
}
|
||||
break;
|
||||
|
||||
/* The following are not yet implemented */
|
||||
/* The following are not yet implemented (return values other than {0,1) */
|
||||
|
||||
case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
|
||||
case SO_LINGER:
|
||||
case SO_SNDBUF: /* Sets send buffer size */
|
||||
case SO_RCVBUF: /* Sets receive buffer size */
|
||||
case SO_ERROR: /* Reports and clears error status. */
|
||||
case SO_LINGER: /* Lingers on a close() if data is present */
|
||||
case SO_RCVBUF: /* Sets receive buffer size */
|
||||
case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */
|
||||
case SO_SNDBUF: /* Sets send buffer size */
|
||||
case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */
|
||||
|
||||
default:
|
||||
|
||||
@@ -129,15 +129,15 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
* is outside of the scope of setsockopt.
|
||||
*/
|
||||
|
||||
case SO_DEBUG: /* Enables recording of debugging information */
|
||||
case SO_BROADCAST: /* Permits sending of broadcast messages */
|
||||
case SO_REUSEADDR: /* Allow reuse of local addresses */
|
||||
case SO_DEBUG: /* Enables recording of debugging information */
|
||||
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
||||
#ifndef CONFIG_NET_TCPPROTO_OPTIONS
|
||||
case SO_KEEPALIVE: /* Verifies TCP connections active by enabling the
|
||||
* periodic transmission of probes */
|
||||
#endif
|
||||
case SO_OOBINLINE: /* Leaves received out-of-band data inline */
|
||||
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
||||
case SO_REUSEADDR: /* Allow reuse of local addresses */
|
||||
{
|
||||
int setting;
|
||||
|
||||
@@ -236,7 +236,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_NET_SOLINGER
|
||||
case SO_LINGER:
|
||||
case SO_LINGER: /* Lingers on a close() if data is present */
|
||||
{
|
||||
FAR struct linger *setting;
|
||||
|
||||
@@ -276,9 +276,9 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
#endif
|
||||
/* The following are not yet implemented */
|
||||
|
||||
case SO_SNDBUF: /* Sets send buffer size */
|
||||
case SO_RCVBUF: /* Sets receive buffer size */
|
||||
case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */
|
||||
case SO_SNDBUF: /* Sets send buffer size */
|
||||
case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */
|
||||
|
||||
/* There options are only valid when used with getopt */
|
||||
|
||||
Reference in New Issue
Block a user