From: Arjen Baart Date: Tue, 3 Sep 2019 15:08:37 +0000 (+0200) Subject: Added nanosleep with float argument X-Git-Tag: 1.0~4 X-Git-Url: http://www.andromeda.nl/gitweb/?a=commitdiff_plain;h=fb531de6ff8607a8cb9fa42d01e7ea017af84832;p=Tachyon.git Added nanosleep with float argument --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4dc9a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.[oa] +Makefile.in diff --git a/doc/design.xml b/doc/design.xml index ab2ba75..ee4c1c0 100644 --- a/doc/design.xml +++ b/doc/design.xml @@ -1,6 +1,10 @@ + + Tachyon + + Introduction @@ -127,6 +131,21 @@ Return the virtual in second since the Epoch. See also time(2). Suspend execution until the time in req is passed. That time is divided by the accelleration set in the Tachyon object. So, if a waiting time of 60 seconds is requested and the accelleration is 10, execution will be actually be suspended for 6 seconds. +The time is specified with nanosecond precision in the struct timespec. It is defined as follows: + + struct timespec + { + time_t tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ + }; + + + + + + +Suspend execution until the time in req is passed. That time is divided by the accelleration set in the Tachyon object. So, if a waiting time of 60 seconds is requested and the accelleration is 10, execution will be actually be suspended for 6 seconds. +The time is specified with nanosecond precision in a floating point number. diff --git a/src/Tachyon.cpp b/src/Tachyon.cpp index 3144a8c..58ef397 100644 --- a/src/Tachyon.cpp +++ b/src/Tachyon.cpp @@ -105,6 +105,21 @@ int Tachyon::nanosleep(struct timespec req) ::nanosleep(&req, NULL); } +int Tachyon::nanosleep(float req) +{ + double seconds; + double nanoseconds; + struct timespec req_t; + + seconds = req / accelleration; + nanoseconds = (seconds - trunc(seconds)) * 1.0e9; + + req_t.tv_sec = trunc(seconds); + req_t.tv_nsec = trunc(nanoseconds); + + ::nanosleep(&req_t, NULL); +} + void Tachyon::settime(time_t sec) { } diff --git a/src/Tachyon.h b/src/Tachyon.h index 9605aee..04eb354 100644 --- a/src/Tachyon.h +++ b/src/Tachyon.h @@ -27,6 +27,7 @@ public: time_t time(void); int nanosleep(struct timespec req); + int nanosleep(float req); void settime(time_t sec); void accellerate(double factor); diff --git a/test/Makefile.am b/test/Makefile.am index c49ca7a..d5e36d4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,13 +1,14 @@ -TESTS = create sleep accellerate +TESTS = create sleep accellerate sleep_float accellerate_float AM_CPPFLAGS = -I../src LDADD = ../src/.libs/libTachyon.la -lrt -lm -check_PROGRAMS = create sleep +check_PROGRAMS = create sleep sleep_float -create_SOURCES = create.cpp -sleep_SOURCES = sleep.cpp +create_SOURCES = create.cpp +sleep_SOURCES = sleep.cpp +sleep_float_SOURCES = sleep_float.cpp clean-local: rm -f sleep.tmp diff --git a/test/accellerate_float b/test/accellerate_float new file mode 100755 index 0000000..f41e818 --- /dev/null +++ b/test/accellerate_float @@ -0,0 +1,22 @@ +#!/bin/bash + +set -m + +PATH=../src:$PATH + +START_TIME=`date +%s` +./sleep_float >sleep.tmp & +sleep 1 +read a b c TACHYON_NAME +#include "Tachyon.h" + +int main() +{ + + Tachyon timebase; + float interval; + + interval = 3.33; + + std::cout << "Tachyon name is " << timebase.name() << "\n"; + std::cout.flush(); + for (int i = 0; i < 10; i++) + { + timebase.nanosleep(interval); + std::cout << "3.3 seconds.\n"; + } +}