source: rtems/cpukit/libcsupport/src/clock.c @ bdbf1ffa

5
Last change on this file since bdbf1ffa was bdbf1ffa, checked in by Sebastian Huber <sebastian.huber@…>, on 09/06/17 at 06:54:24

Implement clock()

Newlib uses _times_r() in clock(). The problem is that the _times_r()
clock frequency is defined by sysconf(_SC_CLK_TCK). The clock frequency
of clock() is the constant CLOCKS_PER_SEC.

FreeBSD uses getrusage() for clock(). Since RTEMS has only one process,
the implementation can be simplified.

Update #3121.

  • Property mode set to 100644
File size: 695 bytes
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <time.h>
20
21#include <rtems/score/basedefs.h>
22#include <rtems/score/timecounter.h>
23
24RTEMS_STATIC_ASSERT( CLOCKS_PER_SEC == 1000000, clocks_per_sec );
25
26clock_t clock( void )
27{
28  struct timeval tv;
29
30  _Timecounter_Microuptime( &tv );
31
32  return (clock_t) (tv.tv_sec - 1) * CLOCKS_PER_SEC + tv.tv_usec;
33}
Note: See TracBrowser for help on using the repository browser.