From 9ef3a9f8b2704693496af12120ea3ab40389bf7b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 24 Oct 2016 02:15:36 +0000 Subject: Add the alarm library, first draft. --- configure | 29 +++++++----- doc/libstddjb/alarm.html | 94 ++++++++++++++++++++++++++++++++++++++ doc/libstddjb/index.html | 1 + package/deps.mak | 7 ++- src/include/skalibs/alarm.h | 13 ++++++ src/include/skalibs/stddjb.h | 1 + src/libstddjb/alarm-internal.h | 14 ++++++ src/libstddjb/alarm_deadline.c | 47 +++++++++++++++++++ src/libstddjb/alarm_disable.c | 41 +++++++++++++++++ src/libstddjb/alarm_milliseconds.c | 61 +++++++++++++++++++++++++ src/libstddjb/alarm_timeout.c | 65 ++++++++++++++++++++++++++ src/libstddjb/alloc-internal.h | 4 +- src/sysdeps/tryitimer.c | 10 ++++ src/sysdeps/trytimer.c | 12 +++++ 14 files changed, 385 insertions(+), 14 deletions(-) create mode 100644 doc/libstddjb/alarm.html create mode 100644 src/include/skalibs/alarm.h create mode 100644 src/libstddjb/alarm-internal.h create mode 100644 src/libstddjb/alarm_deadline.c create mode 100644 src/libstddjb/alarm_disable.c create mode 100644 src/libstddjb/alarm_milliseconds.c create mode 100644 src/libstddjb/alarm_timeout.c create mode 100644 src/sysdeps/tryitimer.c create mode 100644 src/sysdeps/trytimer.c diff --git a/configure b/configure index 96699f6..bb100ed 100755 --- a/configure +++ b/configure @@ -118,19 +118,24 @@ tryldflag () { } choose () { + what="$1" + name="$2" + macro="$3" echo "Checking whether system has $4..." + shift 4 + libs="$*" r=true - case "$1" in - *c*) $CC_AUTO $CPPFLAGS_AUTO $CFLAGS_AUTO -o try$2.o -c src/sysdeps/try$2.c 2>/dev/null || r=false ;; + case "$what" in + *c*) $CC_AUTO $CPPFLAGS_AUTO $CFLAGS_AUTO -o try$name.o -c src/sysdeps/try$name.c 2>/dev/null || r=false ;; esac if $r ; then - case "$1" in - *l*) $CC_AUTO $CFLAGS_AUTO $LDFLAGS_AUTO -o try$2 try$2.o $5 2>/dev/null || r=false ;; + case "$what" in + *l*) $CC_AUTO $CFLAGS_AUTO $LDFLAGS_AUTO -o try$name try$name.o $libs 2>/dev/null || r=false ;; esac fi if $r ; then - case "$1" in - *r*) ./try$2 >/dev/null 2>&1 ; r=$? + case "$what" in + *r*) ./try$name >/dev/null 2>&1 ; r=$? case "$r" in 111) echo " ... test crashed, aborting." ; exit 111 ;; 0) r=true ;; @@ -138,14 +143,14 @@ choose () { esac esac fi - rm -f try$2.o try$2 + rm -f try$name.o try$name if $r ; then - echo "$2: yes" >> $sysdeps/sysdeps - echo "#define ${package_macro_name}_HAS$3" >> $sysdeps/sysdeps.h + echo "$name: yes" >> $sysdeps/sysdeps + echo "#define ${package_macro_name}_HAS$macro" >> $sysdeps/sysdeps.h echo " ... yes" else - echo "$2: no" >> $sysdeps/sysdeps - echo "#undef ${package_macro_name}_HAS$3" >> $sysdeps/sysdeps.h + echo "$name: no" >> $sysdeps/sysdeps + echo "#undef ${package_macro_name}_HAS$macro" >> $sysdeps/sysdeps.h echo " ... no" fi } @@ -490,6 +495,8 @@ EOF choose cl futimes FUTIMES 'futimes()' choose cl arc4random ARC4RANDOM 'arc4random()' choose cl getrandom GETRANDOM 'getrandom()' + choose cl timer TIMER 'timer_create()' $sysclock_lib + choose cl itimer ITIMER 'setitimer()' echo '#endif' >> $sysdeps/sysdeps.h fi diff --git a/doc/libstddjb/alarm.html b/doc/libstddjb/alarm.html new file mode 100644 index 0000000..da14267 --- /dev/null +++ b/doc/libstddjb/alarm.html @@ -0,0 +1,94 @@ + + + + + + skalibs: the alarm library interface + + + + + + +

+libstddjb
+libskarnet
+skalibs
+Software
+skarnet.org +

+ +

The alarm library interface

+ +

+ The following functions are declared in the skalibs/alarm.h header, +and implemented in the libskarnet.a or libskarnet.so library. +

+ +

General information

+ +

+ alarm is a set of primitives to provide the same functionality as +alarm(), +but with sub-second precision. +

+ +

+ Depending on the functionality the underlying system provides, +the precision can be 1 nanosecond (implementation via +timer_settime(), +1 microsecond (implementation via +setitimer(), +or 1 second (fallback implementation with +alarm() +when nothing better can be found). +

+ +

Functions

+ +

+ int alarm_milliseconds (unsigned int n)
+Sets a fuse that will raise a SIGALRM after n milliseconds. +If n is 0, the SIGALRM will be raised instantly. +Returns 1 on success and 0 (and sets errno) on failure. +

+ +

+ int alarm_timeout (tain_t const *tto)
+Sets a fuse that will raise a SIGALRM after some amount +of time has passed. The amount of time is described in +*tto, which is a relative +tain_t, i.e. a structure containing +a relative TAIN64 time. +Returns 1 on success and 0 (and sets errno) on failure. +

+ +

+ int alarm_deadline (tain_t const *deadline)
+Sets a fuse that will raise a SIGALRM when the clock reaches +*deadline, which is an absolute time expressed in +TAI64N format. +Returns 1 on success and 0 (and sets errno) on failure. +

+ +

+ void alarm_disable (void)
+Cancels a previously set fuse. No SIGALRM will be raised. +

+ +

Notes

+ + + + + diff --git a/doc/libstddjb/index.html b/doc/libstddjb/index.html index dfa6f94..6ecfeb2 100644 --- a/doc/libstddjb/index.html +++ b/doc/libstddjb/index.html @@ -45,6 +45,7 @@ including them directly.

Programming