TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
peq_with_get.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 // 12-Jan-2009 John Aynsley Bug fix. sc_time argument to notify should be const
19 // 20-Mar-2009 John Aynsley Add cancel_all() method
20 
21 
22 #ifndef __PEQ_WITH_GET_H__
23 #define __PEQ_WITH_GET_H__
24 
25 #include <systemc>
26 //#include <tlm>
27 #include <map>
28 
29 namespace tlm_utils {
30 
31 template <class PAYLOAD>
33 {
34 public:
35  typedef PAYLOAD transaction_type;
36  typedef std::pair<const sc_core::sc_time, transaction_type*> pair_type;
37 
38 public:
39  peq_with_get(const char* name) : sc_core::sc_object(name)
40  {
41  }
42 
43  void notify(transaction_type& trans, const sc_core::sc_time& t)
44  {
45  m_scheduled_events.insert(pair_type(t + sc_core::sc_time_stamp(), &trans));
46  m_event.notify(t);
47  }
48 
49  void notify(transaction_type& trans)
50  {
51  m_scheduled_events.insert(pair_type(sc_core::sc_time_stamp(), &trans));
52  m_event.notify(); // immediate notification
53  }
54 
55  // needs to be called until it returns 0
57  {
58  if (m_scheduled_events.empty()) {
59  return 0;
60  }
61 
63  if (m_scheduled_events.begin()->first <= now) {
64  transaction_type* trans = m_scheduled_events.begin()->second;
65  m_scheduled_events.erase(m_scheduled_events.begin());
66  return trans;
67  }
68 
69  m_event.notify(m_scheduled_events.begin()->first - now);
70 
71  return 0;
72  }
73 
75  {
76  return m_event;
77  }
78 
79  // Cancel all events from the event queue
80  void cancel_all() {
81  m_scheduled_events.clear();
82  m_event.cancel();
83  }
84 
85 private:
86  std::multimap<const sc_core::sc_time, transaction_type*> m_scheduled_events;
87  sc_core::sc_event m_event;
88 };
89 
90 }
91 
92 #endif
peq_with_get(const char *name)
Definition: peq_with_get.h:39
void notify(transaction_type &trans, const sc_core::sc_time &t)
Definition: peq_with_get.h:43
transaction_type * get_next_transaction()
Definition: peq_with_get.h:56
sc_core::sc_event & get_event()
Definition: peq_with_get.h:74
std::pair< const sc_core::sc_time, transaction_type * > pair_type
Definition: peq_with_get.h:36
const sc_time & sc_time_stamp()
void notify(transaction_type &trans)
Definition: peq_with_get.h:49