blob: efcb46152f68f9ae99e1c079fb3e4beab3315e69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*****************************************************************
|
| Neptune - System :: Win32 Implementation
|
| (c) 2001-2006 Gilles Boccon-Gibod
| Author: Gilles Boccon-Gibod (bok@bok.net)
|
****************************************************************/
/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "e32cmn.h"
#include "e32math.h"
#include "sys/time.h"
#include "NptConfig.h"
#include "NptTypes.h"
#include "NptSystem.h"
#include "NptResults.h"
#include "NptDebug.h"
/*----------------------------------------------------------------------
| globals
+---------------------------------------------------------------------*/
static TInt64 NPT_System_RandomGeneratorSeed = 0;
/*----------------------------------------------------------------------
| NPT_System::GetProcessId
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::GetProcessId(NPT_UInt32& id)
{
//id = getpid();
id = 0;
return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
| NPT_System::GetCurrentTimeStamp
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::GetCurrentTimeStamp(NPT_TimeStamp& now)
{
struct timeval now_tv;
/* get current time from system */
if (gettimeofday(&now_tv, NULL)) {
now.m_Seconds = 0;
now.m_NanoSeconds = 0;
return NPT_FAILURE;
}
/* convert format */
now.m_Seconds = now_tv.tv_sec;
now.m_NanoSeconds = now_tv.tv_usec * 1000;
return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
| NPT_System::Sleep
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::Sleep(const NPT_TimeInterval& duration)
{
TTimeIntervalMicroSeconds32 milliseconds = 1000*duration.m_Seconds + duration.m_NanoSeconds/1000000;
User::After(milliseconds); /* FIXME: this doesn't behave like a normal sleep() where the processor idles. Need to use CTimer much more complicated logic. */
return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
| NPT_System::SleepUntil
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::SleepUntil(const NPT_TimeStamp& when)
{
NPT_TimeStamp now;
GetCurrentTimeStamp(now);
if (when > now) {
NPT_TimeInterval duration = when-now;
return Sleep(duration);
} else {
return NPT_SUCCESS;
}
}
/*----------------------------------------------------------------------
| NPT_System::SetRandomSeed
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::SetRandomSeed(unsigned int seed)
{
NPT_System_RandomGeneratorSeed = seed;
return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
| NPT_System::NPT_System
+---------------------------------------------------------------------*/
NPT_UInt32
NPT_System::GetRandomInteger()
{
if (!NPT_System_RandomGeneratorSeed) {
TTime time;
time.HomeTime();
NPT_System::SetRandomSeed(time.Int64());
}
return Math::Rand(NPT_System_RandomGeneratorSeed);
}
|