Mercurial > projects > dynamin
annotate dynamin/core/unix_environment.d @ 103:73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Tue, 15 May 2012 22:06:02 -0500 |
parents | aa4efef0f0b1 |
children | acdbb30fee7e |
rev | line source |
---|---|
0 | 1 |
2 /* | |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
3 * Copyright Jordan Miner |
0 | 4 * |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
5 * Distributed under the Boost Software License, Version 1.0. |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
6 * (See accompanying file BOOST_LICENSE.txt or copy at |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
7 * http://www.boost.org/LICENSE_1_0.txt) |
0 | 8 * |
9 */ | |
10 | |
11 module dynamin.core.unix_environment; | |
12 | |
13 public import tango.stdc.posix.sys.time; | |
14 public import tango.io.Stdout; | |
15 | |
16 // TODO: v1.0 make a binding to these | |
17 extern(C) { | |
18 int get_nprocs_conf(); | |
19 int get_nprocs(); | |
20 int getitimer(int which, itimerval* value); | |
21 int setitimer(int which, itimerval* value, | |
22 itimerval* ovalue); | |
23 } | |
24 | |
25 enum { | |
26 ITIMER_REAL = 0, | |
27 ITIMER_VIRTUAL = 1, | |
28 ITIMER_PROF = 2 | |
29 } | |
30 | |
31 struct itimerval { | |
32 timeval it_interval; | |
33 timeval it_value; | |
34 } | |
35 | |
36 template EnvironmentBackend() { | |
37 long backend_timevalToMs(timeval* tv) { | |
38 return tv.tv_sec*1000L+tv.tv_usec/1000; | |
39 } | |
40 const long timerSec = 31_536_000*5; // 31,536,000 seconds in 365 days | |
41 static this() { | |
42 itimerval itv; | |
43 itv.it_value.tv_sec = timerSec; | |
44 if(setitimer(ITIMER_REAL, &itv, null)) | |
45 Stdout("setitimer() failed").newline; | |
46 } | |
47 long backend_runningTime() { | |
48 itimerval itv; | |
49 getitimer(ITIMER_REAL, &itv); | |
50 return timerSec*1000-backend_timevalToMs(&itv.it_value); | |
51 } | |
52 long backend_systemTime() { | |
53 timeval tv; | |
54 if(gettimeofday(&tv, null)) | |
55 Stdout("gettimeofday() failed!").newline; | |
56 return backend_timevalToMs(&tv); | |
57 } | |
58 int backend_processorCount() { | |
59 return get_nprocs(); | |
60 } | |
61 long backend_processorTime() { | |
62 return 0; | |
63 } | |
64 } | |
65 |