ruby: Renamed Ruby's EventQueue to RubyEventQueue
[gem5.git] / src / mem / ruby / eventqueue / RubyEventQueue.hh
1
2 /*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * $Id$
32 *
33 * Description: The EventQueue class implements an event queue which
34 * can be trigger events, allowing our simulation to be event driven.
35 *
36 * Currently, the only event we support is a Consumer being signaled
37 * by calling the consumer's wakeup() routine. Adding the event to
38 * the queue does not require a virtual function call, though calling
39 * wakeup() is a virtual function call.
40 *
41 * The method triggerEvents() is called with a global time. All
42 * events which are before or at this time are triggered in timestamp
43 * order. No ordering is enforced for events scheduled to occur at
44 * the same time. Events scheduled to wakeup the same consumer at the
45 * same time are combined into a single event.
46 *
47 * The method scheduleConsumerWakeup() is called with a global time
48 * and a consumer pointer. The event queue will call the wakeup()
49 * method of the consumer at the appropriate time.
50 *
51 * This implementation of EventQueue uses a dynamically sized array
52 * managed as a heap. The algorithms used has O(lg n) for insert and
53 * O(lg n) for extract minimum element. (Based on chapter 7 of Cormen,
54 * Leiserson, and Rivest.) The array is dynamically sized and is
55 * automatically doubled in size when necessary.
56 *
57 */
58
59 #ifndef RUBYEVENTQUEUE_H
60 #define RUBYEVENTQUEUE_H
61
62 #include "Global.hh"
63 #include "Vector.hh"
64
65 class Consumer;
66 template <class TYPE> class PrioHeap;
67 class RubyEventQueueNode;
68
69 class RubyEventQueue {
70 public:
71 // Constructors
72 RubyEventQueue();
73
74 // Destructor
75 ~RubyEventQueue();
76
77 // Public Methods
78
79 Time getTime() const { return m_globalTime; }
80 void scheduleEvent(Consumer* consumer, Time timeDelta) { scheduleEventAbsolute(consumer, timeDelta + m_globalTime); }
81 void scheduleEventAbsolute(Consumer* consumer, Time timeAbs);
82 void triggerEvents(Time t); // called to handle all events <= time t
83 void triggerAllEvents();
84 void print(ostream& out) const;
85 bool isEmpty() const;
86
87 Time getTimeOfLastRecovery() {return m_timeOfLastRecovery;}
88 void setTimeOfLastRecovery(Time t) {m_timeOfLastRecovery = t;}
89
90 // Private Methods
91 private:
92 // Private copy constructor and assignment operator
93 void init();
94 RubyEventQueue(const RubyEventQueue& obj);
95 RubyEventQueue& operator=(const RubyEventQueue& obj);
96
97 // Data Members (m_ prefix)
98 PrioHeap<RubyEventQueueNode>* m_prio_heap_ptr;
99 Time m_globalTime;
100 Time m_timeOfLastRecovery;
101 };
102
103 // Output operator declaration
104 inline extern
105 ostream& operator<<(ostream& out, const RubyEventQueue& obj);
106
107 // ******************* Definitions *******************
108
109 // Output operator definition
110 inline extern
111 ostream& operator<<(ostream& out, const RubyEventQueue& obj)
112 {
113 obj.print(out);
114 out << flush;
115 return out;
116 }
117
118 #endif //EVENTQUEUE_H