comparison deps/Platinum/ThirdParty/Neptune/Source/System/PS3/NptPs3System.cpp @ 0:3425707ddbf6

Initial import (hopefully this mercurial stuff works...)
author fraserofthenight
date Mon, 06 Jul 2009 08:06:28 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3425707ddbf6
1 /*****************************************************************
2 |
3 | Neptune - System :: PS3 Implementation
4 |
5 | (c) 2001-2006 Gilles Boccon-Gibod
6 | Author: Gilles Boccon-Gibod (bok@bok.net)
7 |
8 ****************************************************************/
9
10 /*----------------------------------------------------------------------
11 | includes
12 +---------------------------------------------------------------------*/
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <errno.h>
16 #include <time.h>
17 #include <sys/timer.h>
18 #include <sys/sys_time.h>
19 #include <unistd.h>
20
21 #include "NptConfig.h"
22 #include "NptTypes.h"
23 #include "NptSystem.h"
24 #include "NptResults.h"
25 #include "NptDebug.h"
26
27 /*----------------------------------------------------------------------
28 | NPT_System::GetProcessId
29 +---------------------------------------------------------------------*/
30 NPT_Result
31 NPT_System::GetProcessId(NPT_Integer& id)
32 {
33 id = 0;
34 return NPT_SUCCESS;
35 }
36
37 /*----------------------------------------------------------------------
38 | NPT_System::GetCurrentTimeStamp
39 +---------------------------------------------------------------------*/
40 NPT_Result
41 NPT_System::GetCurrentTimeStamp(NPT_TimeStamp& now)
42 {
43 sys_time_sec_t sec;
44 sys_time_nsec_t nsec;
45
46 int result = sys_time_get_current_time(&sec, &nsec);
47 if (result != CELL_OK){
48 now.m_Seconds = 0;
49 now.m_NanoSeconds = 0;
50 return NPT_FAILURE;
51 }
52
53 /* convert format */
54 now.m_Seconds = sec;
55 now.m_NanoSeconds = nsec;
56
57 return NPT_SUCCESS;
58 }
59
60 /*----------------------------------------------------------------------
61 | NPT_System::Sleep
62 +---------------------------------------------------------------------*/
63 NPT_Result
64 NPT_System::Sleep(const NPT_TimeInterval& duration)
65 {
66 unsigned long usecs = 1000000*duration.m_Seconds + duration.m_NanoSeconds/1000;
67 sys_timer_usleep(usecs);
68
69 return NPT_SUCCESS;
70 }
71
72 /*----------------------------------------------------------------------
73 | NPT_System::SleepUntil
74 +---------------------------------------------------------------------*/
75 NPT_Result
76 NPT_System::SleepUntil(const NPT_TimeStamp& when)
77 {
78 NPT_TimeStamp now;
79 GetCurrentTimeStamp(now);
80 if (when > now) {
81 NPT_TimeInterval duration = when-now;
82 return NPT_System::Sleep(duration);
83 } else {
84 return NPT_SUCCESS;
85 }
86 }
87
88 /*----------------------------------------------------------------------
89 | NPT_System::SetRandomSeed
90 +---------------------------------------------------------------------*/
91 NPT_Result
92 NPT_System::SetRandomSeed(unsigned int seed)
93 {
94 srand(seed);
95 return NPT_SUCCESS;
96 }
97
98 /*----------------------------------------------------------------------
99 | NPT_System::GetRandomInteger
100 +---------------------------------------------------------------------*/
101 NPT_Integer
102 NPT_System::GetRandomInteger()
103 {
104 static bool seeded = false;
105 if (!seeded) {
106 NPT_TimeStamp now;
107 GetCurrentTimeStamp(now);
108 srand(now.m_NanoSeconds);
109 seeded = true;
110 }
111
112 return rand();
113 }