Skip to content

Commit 69f610b

Browse files
Syntactic cleanups
Signed-off-by: Mark Burton <[email protected]>
1 parent 727e66f commit 69f610b

File tree

7 files changed

+121
-122
lines changed

7 files changed

+121
-122
lines changed

src/sysc/kernel/sc_event.h

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -275,64 +275,44 @@ class SC_API sc_event
275275
friend class sc_join;
276276
friend class sc_trace_file;
277277

278-
class pending_helper : public sc_prim_channel
279-
{
280-
std::mutex mutex;
281-
class sc_event *event;
282-
283-
bool valid=false;
284-
bool cancel=false;
285-
bool timed=false;
286-
sc_time time;
287-
288-
void update(void) {
289-
mutex.lock();
290-
if (valid) {
291-
if (cancel) {
292-
valid=false;
293-
mutex.unlock();
294-
event->cancel();
295-
} else {
296-
valid=false;
297-
auto t=time;
298-
auto t_valid=timed;
299-
mutex.unlock();
300-
if (t_valid) {
301-
event->notify(t);
302-
} else {
303-
event->notify();
304-
}
305-
}
278+
class pending_helper : public sc_prim_channel {
279+
std::mutex mutex;
280+
class sc_event *event;
281+
282+
bool cancel = false;
283+
sc_time time;
284+
285+
void update(void) {
286+
std::lock_guard<std::mutex> lg(mutex);
287+
if (cancel) {
288+
event->cancel();
289+
} else {
290+
if (time < sc_time_stamp()) {
291+
event->notify(SC_ZERO_TIME);
306292
} else {
307-
mutex.unlock();
293+
event->notify(time-sc_time_stamp());
308294
}
309295
}
310-
311-
public:
312-
void pending_notify(sc_time t) {
313-
std::lock_guard<std::mutex> lg(mutex);
314-
time=t;
315-
timed=true;
316-
valid=true;
317-
async_request_update();
318-
}
319-
void pending_notify() {
320-
std::lock_guard<std::mutex> lg(mutex);
321-
timed=false;
322-
valid=true;
323-
async_request_update();
324-
}
325-
void pending_cancel() {
326-
std::lock_guard<std::mutex> lg(mutex);
327-
valid=true;
328-
cancel=true;
329-
async_request_update();
330-
}
331-
332-
pending_helper(sc_event *e) : sc_prim_channel(true) {
333-
event=e;
334-
}
335-
296+
}
297+
298+
public:
299+
void pending_notify(sc_time t) {
300+
std::lock_guard<std::mutex> lg(mutex);
301+
time = t+sc_time_stamp();
302+
async_request_update();
303+
}
304+
void pending_notify() {
305+
std::lock_guard<std::mutex> lg(mutex);
306+
time = SC_ZERO_TIME;
307+
async_request_update();
308+
}
309+
void pending_cancel() {
310+
std::lock_guard<std::mutex> lg(mutex);
311+
cancel = true;
312+
async_request_update();
313+
}
314+
315+
pending_helper(sc_event *e) : sc_prim_channel(true) { event = e; }
336316
};
337317
friend class pending_helper;
338318
public:

src/sysc/utils/sc_ob_event.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
/*****************************************************************************
1818
19-
sc_ob_event.h -- Event that fires only when there are subsequent events
19+
sc_ob_event.h -- Event that fires only when the simulator arrives at the
20+
notification time, or there are subsequent events
2021
2122
Original Author: Mark burton
2223
@@ -30,9 +31,6 @@
3031
#define _SC_OB_EVENT_
3132

3233
#include <systemc>
33-
#include <tlm>
34-
35-
#include <string>
3634

3735
namespace sc_core {
3836
class sc_ob_event : public sc_core::sc_module,
@@ -75,19 +73,20 @@ class sc_ob_event : public sc_core::sc_module,
7573
m_scheduled = sc_core::sc_time_stamp() + delay;
7674
sc_core::sc_register_stage_callback(*this, sc_core::SC_POST_UPDATE);
7775
}
78-
76+
void cancel() {
77+
sc_core::sc_event::cancel();
78+
sc_core::sc_unregister_stage_callback(*this, sc_core::SC_POST_UPDATE);
79+
}
7980
void stage_callback(const sc_core::sc_stage &stage) {
80-
// if (sc_core::sc_pending_activity()) { // should the event fire is there is pending activity, or if we arrive at the time?
81-
sc_core::sc_time pending = sc_core::sc_time_stamp();
82-
if (sc_core::sc_pending_activity_at_future_time()) {
83-
pending += sc_core::sc_time_to_pending_activity();
84-
}
81+
sc_core::sc_time pending = sc_core::sc_time_stamp();
82+
if (sc_core::sc_pending_activity_at_future_time()) {
83+
pending += sc_core::sc_time_to_pending_activity();
84+
}
8585

86-
if (pending >= m_scheduled) {
87-
m_th.resume();
88-
sc_core::sc_unregister_stage_callback(*this, sc_core::SC_POST_UPDATE);
89-
}
90-
// }
86+
if (pending >= m_scheduled) {
87+
m_th.resume();
88+
sc_core::sc_unregister_stage_callback(*this, sc_core::SC_POST_UPDATE);
89+
}
9190
}
9291

9392
~sc_ob_event() {}

src/sysc/utils/sc_on_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class sc_on_context : public sc_core::sc_module
223223
}
224224
}
225225

226-
m_jobs_handler_event.notify(sc_core::SC_ZERO_TIME);
226+
m_jobs_handler_event.notify();
227227

228228
if (wait) {
229229
/* Wait for job completion */

src/sysc/utils/sc_parallel.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
namespace sc_core {
4040

41+
template <typename T, class SYNC_POLICY> class sc_parallel;
4142
/**
4243
* @brief Simcontext handler, encapsulates a simcontext
4344
* This is required for the templated class to work, and hence is required in
@@ -46,7 +47,7 @@ namespace sc_core {
4647
*/
4748
template <class SYNC_POLICY = sc_core::sc_sync_policy_in_sync>
4849
class _internal_simcontext_handler {
49-
50+
template <typename T, class S> friend class sc_parallel;
5051
/**
5152
* @brief Helper to capture start of simulation and start std::thread
5253
*
@@ -131,6 +132,7 @@ class _internal_simcontext_handler {
131132
sc_sync_windowed<SYNC_POLICY> *m_sync_child;
132133
};
133134

135+
private:
134136
sc_core::sc_simcontext *m_old_simcontext =
135137
sc_get_curr_simcontext(); // Side effect create simcontext if we are the
136138
// first module
@@ -139,7 +141,6 @@ class _internal_simcontext_handler {
139141
control_module m_ctrl_module;
140142
sc_sync_windowed<SYNC_POLICY> m_sync_parent;
141143

142-
public:
143144
void use_simcontext() {
144145
assert(sc_curr_simcontext != &m_simcontext);
145146
m_old_simcontext = sc_curr_simcontext;
@@ -148,6 +149,7 @@ class _internal_simcontext_handler {
148149

149150
void revert_simcontext() { sc_curr_simcontext = m_old_simcontext; }
150151

152+
public:
151153
_internal_simcontext_handler()
152154
: m_ctrl_module("ctrl_module", this), m_sync_parent("sync_parent") {
153155
SYNC_POLICY sync_policy;

src/sysc/utils/sc_sync_window.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ class sc_sync_windowed : public sc_core::sc_module,
7979
struct window {
8080
sc_core::sc_time from;
8181
sc_core::sc_time to;
82-
bool operator==(window other) {
82+
bool operator==(const window &other) const {
8383
return other.to == to && other.from == from;
8484
}
8585
};
8686

87-
const struct window zero_window = {sc_core::SC_ZERO_TIME,
87+
static inline const struct window zero_window = {sc_core::SC_ZERO_TIME,
8888
sc_core::SC_ZERO_TIME};
89-
const struct window open_window = {sc_core::SC_ZERO_TIME,
89+
static inline const struct window open_window = {sc_core::SC_ZERO_TIME,
9090
sc_core::sc_max_time()};
9191

9292
private:
@@ -98,7 +98,6 @@ class sc_sync_windowed : public sc_core::sc_module,
9898

9999
void do_other_async_set_window_fn(window w) {
100100
if (m_other_async_set_window_fn) {
101-
auto now = sc_core::sc_time_stamp();
102101
m_other_async_set_window_fn(w);
103102
}
104103
}
@@ -109,6 +108,8 @@ class sc_sync_windowed : public sc_core::sc_module,
109108
auto now = sc_core::sc_time_stamp();
110109
auto to = m_window.to;
111110

111+
/* The step helper has to handle both suspend and resume (because of
112+
* SystemC) */
112113
if (now >= to) {
113114
sc_core::sc_unsuspend_all(); // such that pending activity is valid if
114115
// it's needed below.
@@ -122,17 +123,12 @@ class sc_sync_windowed : public sc_core::sc_module,
122123
sc_core::sc_suspend_all();
123124

124125
} else {
126+
/* the only way to get here is if we have a 'new' window from the other
127+
* side. we are here just to unsuspend */
125128
sc_core::sc_unsuspend_all();
126129
if (!policy.keep_alive())
127130
async_detach_suspending();
128-
129-
// We are about to advance to the next event, so may as well set that as
130-
// the window now
131-
do_other_async_set_window_fn(
132-
{now + (sc_core::sc_pending_activity()
133-
? sc_core::sc_time_to_pending_activity()
134-
: sc_core::SC_ZERO_TIME),
135-
now + policy.quantum()});
131+
//do_other_async_set_window_fn({now, now + policy.quantum()});
136132

137133
/* Re-notify event - maybe presumably moved */
138134
m_step_ev.notify(to - now);
@@ -162,6 +158,9 @@ class sc_sync_windowed : public sc_core::sc_module,
162158
}
163159
/* let stepper handle suspend/resume, must time notify */
164160
m_update_ev.notify(sc_core::SC_ZERO_TIME);
161+
// std::ostringstream s;
162+
// s << "Got Window: " << m_window.from << " - " << m_window.to;
163+
// SC_REPORT_INFO(sc_core::sc_module::name(), s.str().c_str());
165164
}
166165

167166
public:
@@ -171,7 +170,7 @@ class sc_sync_windowed : public sc_core::sc_module,
171170
* Input: window - Window to set for sync. Sweep till the 'from' and step to
172171
* the 'to'.
173172
*/
174-
void async_set_window(window w) {
173+
void async_set_window(const window &w) {
175174
/* Only accept updated windows so we dont re-send redundant updates
176175
* safe at this point to compair against m_window as we took the lock
177176
*/
@@ -192,9 +191,7 @@ class sc_sync_windowed : public sc_core::sc_module,
192191
"m_other_async_set_window_fn was already registered or other "
193192
"sc_sync_windowed was already bound!");
194193
}
195-
m_other_async_set_window_fn = [other](const window &w) {
196-
other->async_set_window(w);
197-
};
194+
m_other_async_set_window_fn = std::bind(&sc_sync_windowed::async_set_window, other, std::placeholders::_1);
198195
}
199196
void register_sync_cb(std::function<void(const window &)> fn) {
200197
if (m_other_async_set_window_fn) {
@@ -216,7 +213,7 @@ class sc_sync_windowed : public sc_core::sc_module,
216213
dont_initialize();
217214
sensitive << m_step_ev << m_update_ev;
218215

219-
m_step_ev.notify(sc_core::SC_ZERO_TIME);
216+
m_step_ev.notify(policy.quantum());
220217

221218
this->sc_core::sc_prim_channel::async_attach_suspending();
222219
}

src/tlm_utils/simple_target_socket.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ class simple_target_socket_b
313313
// forward call
314314
sc_assert(m_mod);
315315
if (!m_on_ctx.is_on_sysc()) {
316+
sc_time our_time=sc_core::sc_time_stamp();
317+
sc_time their_time;
316318
m_on_ctx.run(
317-
[this, &trans, &t]() { (m_mod->*m_b_transport_ptr)(trans, t); });
319+
[this, &trans, &t, &our_time, &their_time]() { if (our_time>sc_time_stamp()) wait(our_time-sc_time_stamp()); (m_mod->*m_b_transport_ptr)(trans, t); their_time=sc_time_stamp(); });
320+
if (their_time>sc_time_stamp()) wait(their_time-sc_time_stamp());
318321
} else {
319322
(m_mod->*m_b_transport_ptr)(trans, t);
320323
}

0 commit comments

Comments
 (0)