| 1 | /* Hey EMACS -*- linux-c -*- */ |
| 2 | /* $Id$ */ |
| 3 | |
| 4 | /* libticables2 - link cable library, a part of the TiLP project |
| 5 | * Copyright (C) 1999-2005 Romain Lievin |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 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. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | Some explanations about this unit: I use different functions for measuring |
| 24 | time depending on the platform type. |
| 25 | In fact, it appears that the Win32 clock() function of <time.h> is 600 times |
| 26 | slower than the Win32 GetTickCount() function of <windows.h>. |
| 27 | As a consequency of this fact, the speed rate was divided by 4. |
| 28 | |
| 29 | A great thanks to Timothy Singer <[email protected]>, the |
| 30 | FastLink's developer. He sent to me her routines so that I can compare with |
| 31 | mine. This allowed me to find why my routines was so slow ! |
| 32 | */ |
| 33 | |
| 34 | #ifndef __CABLE_TIMEOUT__ |
| 35 | #define __CABLE_TIMEOUT__ |
| 36 | |
| 37 | /* |
| 38 | Platform independant time measurement (in milli-seconds) |
| 39 | and timeout management (in tenth of seconds) |
| 40 | - TO_START: retrieve time (starting point) |
| 41 | - TO_CURRENT: return the number of milli-seconds elapsed since TO_START() |
| 42 | - TO_ELAPSED: return TRUE if max tenth of seconds have elapsed |
| 43 | */ |
| 44 | |
| 45 | // I don't want to include windows.h here. |
| 46 | //# include <windows.h> |
| 47 | //typedef DWORD tiTIME; |
| 48 | typedef unsigned long tiTIME; |
| 49 | |
| 50 | #if defined(__WIN32__) && !defined(__MINGW32__) |
| 51 | |
| 52 | # include <sysinfoapi.h> |
| 53 | # define TO_START(ref) { (ref) = GetTickCount(); } |
| 54 | # define TO_CURRENT(ref) ( GetTickCount() - (ref) ) |
| 55 | # define TO_ELAPSED(ref, max) ( TO_CURRENT(ref) > (100UL*(max)) ) |
| 56 | |
| 57 | #else |
| 58 | |
| 59 | # include <time.h> |
| 60 | # define TO_START(ref) { (ref) = ((1000*clock()) / CLOCKS_PER_SEC); } |
| 61 | # define TO_CURRENT(ref) ( (1000*clock()) / CLOCKS_PER_SEC - (ref) ) |
| 62 | # define TO_ELAPSED(ref, max) ( TO_CURRENT(ref) > (100UL*(max)) ) |
| 63 | |
| 64 | #endif |
| 65 | |
| 66 | #endif |