1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add clock(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-05-15 15:00:48 +02:00
parent 0903f4edc2
commit ad51b5a070
3 changed files with 12 additions and 9 deletions

View file

@ -174,7 +174,6 @@ canonicalize_file_name.o \
chdir.o \ chdir.o \
chmod.o \ chmod.o \
chown.o \ chown.o \
clock.o \
close.o \ close.o \
confstr.o \ confstr.o \
$(CPUDIR)/calltrace.o \ $(CPUDIR)/calltrace.o \
@ -355,6 +354,7 @@ time/clock_getres.o \
time/clock_gettime.o \ time/clock_gettime.o \
time/clock_gettimeres.o \ time/clock_gettimeres.o \
time/clock_nanosleep.o \ time/clock_nanosleep.o \
time/clock.o \
time/clock_settime.o \ time/clock_settime.o \
time/clock_settimeres.o \ time/clock_settimeres.o \
time/nanosleep.o \ time/nanosleep.o \

View file

@ -62,7 +62,7 @@ __BEGIN_DECLS
@include(NULL.h) @include(NULL.h)
#define CLOCKS_PER_SEC ((clock_t) 1000000) #define CLOCKS_PER_SEC 1000000l
__END_DECLS __END_DECLS
#include <sortix/clock.h> #include <sortix/clock.h>

View file

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2013
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -17,16 +17,19 @@
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>. along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
clock.cpp time/clock.cpp
Determine processor time. Get process execution time.
*******************************************************************************/ *******************************************************************************/
#include <errno.h>
#include <time.h> #include <time.h>
extern "C" clock_t clock(void) // TODO: This function is crap and has been replaced by clock_gettime.
extern "C" clock_t clock()
{ {
errno = ENOTSUP; struct timespec now;
if ( clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now) < 0 )
return -1; return -1;
static_assert(CLOCKS_PER_SEC == 1000000, "CLOCKS_PER_SEC == 1000000");
return (clock_t) now.tv_sec * 1000000 + (clock_t) now.tv_sec / 1000;
} }