/[ascend]/branches/adrian/ascend/general/tm_time.c
ViewVC logotype

Contents of /branches/adrian/ascend/general/tm_time.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2930 - (show annotations) (download) (as text)
Mon Jun 1 11:17:13 2015 UTC (7 years, 5 months ago) by adrian
File MIME type: text/x-csrc
File size: 2201 byte(s)
Fixed windows real time library issue
1 /* ASCEND modelling environment
2 Copyright (C) 1997 Carnegie Mellon University
3 Copyright (C) 2015 John Pye
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *//*
18 Time module by Karl Westerberg, created: 6/1990
19 Last in CVS: $Date: 2000/01/25 02:21:26 $ $Author: ballan $
20 */
21
22 #include <sys/time.h>
23 #include "platform.h"
24 #include "panic.h"
25 #include "tm_time.h"
26
27 static boolean f_first = TRUE;
28
29 /* the code with clock_gettime() cannot be used on windows due to posix compability */
30 #ifdef __WIN32__
31 double tm_cpu_time(void)
32 {
33 static clock_t ref;
34 static double dref;
35 clock_t now;
36 double dnow;
37
38 if( f_first ) {
39 ref = clock();
40 dref = (double) ref;
41 f_first = FALSE;
42 }
43 now = clock();
44 dnow = (double) now;
45
46 return((dnow - dref) / CLOCKS_PER_SEC);
47 }
48 #else
49 double tm_cpu_time(void){
50 static struct timespec ref;
51 struct timespec now;
52
53 if( f_first ) {
54 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ref);
55 f_first = FALSE;
56 }
57 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now);
58 return (now.tv_sec - ref.tv_sec) + 1e-9*(now.tv_nsec - ref.tv_nsec);
59 }
60 #endif
61
62 double tm_reset_cpu_time(void)
63 {
64 f_first = TRUE;
65 return tm_cpu_time();
66 }
67
68 void tm_cpu_time_ftn_(double *t)
69 {
70 asc_assert(NULL != t);
71 *t = tm_cpu_time();
72 }
73
74 void aftime_(double *t)
75 {
76 asc_assert(NULL != t);
77 *t = tm_cpu_time();
78 }
79
80 void tm_cpu_time_ftn(double *t)
81 {
82 asc_assert(NULL != t);
83 *t = tm_cpu_time();
84 }
85
86 void aftime(double *t)
87 {
88 asc_assert(NULL != t);
89 *t = tm_cpu_time();
90 }
91
92 void TM_CPU_TIME_FTN(double *t)
93 {
94 asc_assert(NULL != t);
95 *t = tm_cpu_time();
96 }
97
98 void AFTIME(double *t)
99 {
100 asc_assert(NULL != t);
101 *t = tm_cpu_time();
102 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22