0
|
1 // Written in the D programming language
|
|
2 // www.digitalmars.com/d/
|
|
3
|
|
4 /*
|
|
5 * The contents of this file are subject to the Mozilla Public License Version
|
|
6 * 1.1 (the "License"); you may not use this file except in compliance with
|
|
7 * the License. You may obtain a copy of the License at
|
|
8 * http://www.mozilla.org/MPL/
|
|
9 *
|
|
10 * Software distributed under the License is distributed on an "AS IS" basis,
|
|
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
12 * for the specific language governing rights and limitations under the
|
|
13 * License.
|
|
14 *
|
|
15 * The Original Code is the Dynamin library.
|
|
16 *
|
|
17 * The Initial Developer of the Original Code is Jordan Miner.
|
|
18 * Portions created by the Initial Developer are Copyright (C) 2007-2009
|
|
19 * the Initial Developer. All Rights Reserved.
|
|
20 *
|
|
21 * Contributor(s):
|
|
22 * Jordan Miner <jminer7@gmail.com>
|
|
23 *
|
|
24 */
|
|
25
|
|
26 module dynamin.core.unix_environment;
|
|
27
|
|
28 public import tango.stdc.posix.sys.time;
|
|
29 public import tango.io.Stdout;
|
|
30
|
|
31 // TODO: v1.0 make a binding to these
|
|
32 extern(C) {
|
|
33 int get_nprocs_conf();
|
|
34 int get_nprocs();
|
|
35 int getitimer(int which, itimerval* value);
|
|
36 int setitimer(int which, itimerval* value,
|
|
37 itimerval* ovalue);
|
|
38 }
|
|
39
|
|
40 enum {
|
|
41 ITIMER_REAL = 0,
|
|
42 ITIMER_VIRTUAL = 1,
|
|
43 ITIMER_PROF = 2
|
|
44 }
|
|
45
|
|
46 struct itimerval {
|
|
47 timeval it_interval;
|
|
48 timeval it_value;
|
|
49 }
|
|
50
|
|
51 template EnvironmentBackend() {
|
|
52 long backend_timevalToMs(timeval* tv) {
|
|
53 return tv.tv_sec*1000L+tv.tv_usec/1000;
|
|
54 }
|
|
55 const long timerSec = 31_536_000*5; // 31,536,000 seconds in 365 days
|
|
56 static this() {
|
|
57 itimerval itv;
|
|
58 itv.it_value.tv_sec = timerSec;
|
|
59 if(setitimer(ITIMER_REAL, &itv, null))
|
|
60 Stdout("setitimer() failed").newline;
|
|
61 }
|
|
62 long backend_runningTime() {
|
|
63 itimerval itv;
|
|
64 getitimer(ITIMER_REAL, &itv);
|
|
65 return timerSec*1000-backend_timevalToMs(&itv.it_value);
|
|
66 }
|
|
67 long backend_systemTime() {
|
|
68 timeval tv;
|
|
69 if(gettimeofday(&tv, null))
|
|
70 Stdout("gettimeofday() failed!").newline;
|
|
71 return backend_timevalToMs(&tv);
|
|
72 }
|
|
73 int backend_processorCount() {
|
|
74 return get_nprocs();
|
|
75 }
|
|
76 long backend_processorTime() {
|
|
77 return 0;
|
|
78 }
|
|
79 }
|
|
80
|