Moved REPEAT-*-DECREASING-TIMEOUT and GETTIME into IOLIB-POSIX.
[iolib.git] / io-multiplex / time.lisp
blob98da06a30e4ad422a95fbb5fb3ed34cf52148809
1 ;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 ;; Copyright (C) 2006, 2007 Stelian Ionescu
4 ;;
5 ;; This code is free software; you can redistribute it and/or
6 ;; modify it under the terms of the version 2.1 of
7 ;; the GNU Lesser General Public License as published by
8 ;; the Free Software Foundation, as clarified by the
9 ;; preamble found here:
10 ;; http://opensource.franz.com/preamble.html
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU Lesser General
18 ;; Public License along with this library; if not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA
22 (in-package :io.multiplex)
24 (deftype timeout ()
25 'double-float)
28 ;;; Break a real timeout into seconds and microseconds.
29 (defun decode-timeout (timeout)
30 (typecase timeout
31 (integer (values timeout 0))
32 (null nil)
33 (real
34 (multiple-value-bind (q r) (truncate (coerce timeout 'double-float))
35 (declare (type unsigned-byte q)
36 (type double-float r))
37 (values q (the (values unsigned-byte t) (truncate (* r 1d6))))))
39 (error "Timeout is not a real number or NIL: ~S" timeout))))
42 (defun normalize-timeout (timeout)
43 (when timeout
44 (assert (not (minusp timeout)))
45 (etypecase timeout
46 ((or integer real) (coerce timeout 'double-float)))))
49 (defun abs-timeout (timeout)
50 (when timeout
51 (+ (et::gettime) (normalize-timeout timeout))))
54 (defun calc-min-timeout (t1 t2)
55 (if t1
56 (if t2
57 (min t1 t2)
58 t1)
59 t2))