-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimtime.cc
93 lines (76 loc) · 1.98 KB
/
simtime.cc
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
#include <assert.h>
#include <algorithm>
#include "simtime.h"
//#include "magic.h"
using namespace std;
SimTime::Queue SimTime::_q;
double SimTime::_now = 0;
double* SimTime::_deadline = NULL;
static double logtime = 100;
SimEvent::SimEvent( EventType type, double t )
: _type(type)
, _timestamp(t)
{ }
SimEvent::~SimEvent()
{ }
void SimTime::insert( SimEvent* ev )
{
_q.insert( ev );
}
SimEvent* SimTime::get( )
{
if( _q.empty() ) return NULL;
Queue_it it = _q.begin( );
SimEvent* ret = *it;
_q.erase(it);
assert( ret->_timestamp >= _now );
_now = std::max<double>( _now, ret->_timestamp );
if( _deadline && _now > *_deadline ) return NULL;
if( _now > logtime )
{
cerr << "Time: " << _now << endl;
//Magic::printNumbersInGroups( cerr );
// logtime += 100;
logtime *= 2;
}
return ret;
}
double SimTime::Now( )
{
return _now;
}
void SimTime::reset( )
{
/* for( int i=0; i<10; i++ )
cout << endl;
for( int i=0; i<10; i++ )
cout << "########################################################" << endl;
for( int i=0; i<10; i++ )
cout << "## ##" << endl;
cout << "## Resetting SIMTIME ##" << endl;
for( int i=0; i<10; i++ )
cout << "## ##" << endl;
for( int i=0; i<10; i++ )
cout << "########################################################" << endl;
for( int i=0; i<10; i++ )
cout << endl;
*/
_now = 0;
// cout << __FILE__ << ":" << __LINE__ << " DEBUG EXIT" << endl;
// exit( 0 );
}
void SimTime::setDeadline( double d )
{
_deadline = new double(d);
}
void SimTime::dump( ostream& ostr )
{
ostr << "Now: " << _now << " ";
Queue_it qit, qend;
qit = _q.begin( );
qend = _q.end();
for( ;qit!=qend; qit++ )
{
ostr << (*qit)->_timestamp << " ";
}
}