SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_process_handle.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 /*****************************************************************************
19 
20  sc_process_handle.h -- Process access support.
21 
22  Original Author: Andy Goodrich, Forte Design Systems, 17 June 2003
23 
24 
25  CHANGE LOG AT THE END OF THE FILE
26  *****************************************************************************/
27 
28 // $Log: sc_process_handle.h,v $
29 // Revision 1.21 2011/08/26 21:54:04 acg
30 // Torsten Maehne: Simplify use of dynamic_cast<> for initializing m_target.
31 //
32 // Revision 1.20 2011/08/26 20:46:10 acg
33 // Andy Goodrich: moved the modification log to the end of the file to
34 // eliminate source line number skew when check-ins are done.
35 //
36 
37 #if !defined(sc_process_handle_h_INCLUDED)
38 #define sc_process_handle_h_INCLUDED
39 
40 #include "sysc/kernel/sc_module.h"
41 
42 namespace sc_core {
43 
44 // forward operator declarations:
45 
46 class sc_process_handle;
47 bool
48 operator == ( const sc_process_handle& left, const sc_process_handle& right );
49 bool
50 operator != ( const sc_process_handle& left, const sc_process_handle& right );
51 bool
52 operator < ( const sc_process_handle& left, const sc_process_handle& right );
53 
54 
55 
56 /**************************************************************************/
63 class sc_simcontext;
66 
67  friend bool operator == ( const this_type& left, const this_type& right );
68  friend bool operator != ( const this_type& left, const this_type& right );
69  friend bool operator < ( const this_type& left, const this_type& right );
70  friend class sc_object;
71  friend class sc_join;
72  friend class sc_module;
73 
74  // 04/07/2015 GL: a new sc_channel class is derived from sc_module
75  friend class sc_channel;
76 
77  friend class sc_reset;
78  friend class sc_sensitive;
79  friend class sc_sensitive_pos;
80  friend class sc_sensitive_neg;
81  friend class sc_thread_process;
82 
83  public:
84  inline sc_process_handle();
85  inline explicit sc_process_handle( sc_object* object_p );
86  inline explicit sc_process_handle( sc_process_b* process_p );
87  inline sc_process_handle( const sc_process_handle& orig );
88  inline ~sc_process_handle();
90  inline void swap( sc_process_handle& other );
91 
92  public:
93  inline void disable(
95  inline bool dynamic() const;
96  inline void enable(
98  inline const std::vector<sc_event*>& get_child_events() const;
99  inline const std::vector<sc_object*>& get_child_objects() const;
100  inline sc_object* get_parent_object() const;
101  inline sc_object* get_process_object() const;
102  inline bool is_unwinding() const;
103  inline void kill(
105  inline const char* name() const;
106  inline sc_curr_proc_kind proc_kind() const;
107  inline void reset(
109  inline sc_event& reset_event() const;
110  inline void resume(
112  inline void suspend(
114  inline void sync_reset_off(
116  inline void sync_reset_on(
118  inline sc_event& terminated_event();
119  inline bool terminated() const;
120  template<typename EXCEPT>
121  inline void throw_it( const EXCEPT& exception,
123  inline bool valid() const;
124 
125  public: // implementation specific methods:
126  inline std::string dump_state() const;
127 
128  protected:
129  inline bool dont_initialize() const
130  { return m_target_p ? m_target_p->dont_initialize() : false; }
131  inline void dont_initialize( bool dont );
132 
133  public:
134  operator sc_process_b* ()
135  { return m_target_p; }
136  operator sc_cthread_handle ();
137  operator sc_method_handle ();
138  operator sc_thread_handle ();
139 
140  protected:
141  sc_process_b* m_target_p; // Target for this object instance.
142 
143  protected:
144  static std::vector<sc_event*> empty_event_vector; // If m_target_p == 0.
145  static std::vector<sc_object*> empty_object_vector; // If m_target_p == 0.
146  static sc_event non_event; // If m_target_p == 0.
147 };
148 
149 inline bool operator == (
150  const sc_process_handle& left, const sc_process_handle& right )
151 {
152  return (left.m_target_p != 0) && (right.m_target_p != 0) &&
153  (left.m_target_p == right.m_target_p);
154 }
155 
156 inline bool operator != (
157  const sc_process_handle& left, const sc_process_handle& right )
158 {
159  return (left.m_target_p == 0) || (right.m_target_p == 0) ||
160  (left.m_target_p != right.m_target_p);
161 }
162 
163 inline bool operator < (
164  const sc_process_handle& left, const sc_process_handle& right )
165 {
166  return left.m_target_p < right.m_target_p;
167 }
168 
169 //------------------------------------------------------------------------------
170 //"sc_process_handle::sc_process_handle - non-pointer constructor"
171 //
172 // This version of the object instance constructor for this class creates
173 // an object instance whose target needs to be supplied via an assignment.
174 //------------------------------------------------------------------------------
175 inline sc_process_handle::sc_process_handle() : m_target_p(0)
176 {
177 }
178 
179 //------------------------------------------------------------------------------
180 //"sc_process_handle::sc_process_handle - pointer constructor"
181 //
182 // This version of the object instance constructor for this class creates
183 // an object instance whose target is the supplied sc_object instance.
184 // The supplied sc_object must in fact be an sc_process_b instance.
185 // object_p -> sc_object instance this is handle for.
186 //------------------------------------------------------------------------------
188  m_target_p(DCAST<sc_process_b*>(object_p))
189 {
190  if ( m_target_p ) m_target_p->reference_increment();
191 }
192 
193 //------------------------------------------------------------------------------
194 //"sc_process_handle::sc_process_handle - pointer constructor"
195 //
196 // This version of the object instance constructor for this class creates
197 // an object instance whose target is the supplied sc_process_b instance.
198 // This saves a dynamic cast compared to the sc_object* case.
199 // process_p -> process instance this is handle for.
200 //------------------------------------------------------------------------------
202  m_target_p(process_p)
203 {
204  if ( m_target_p ) m_target_p->reference_increment();
205 }
206 
207 //------------------------------------------------------------------------------
208 //"sc_process_handle::sc_process_handle - copy constructor"
209 //
210 // This version of the object instance constructor for this class provides
211 // the copy constructor for the class. It clones the supplied original
212 // handle and increments the references to its target.
213 // orig = sc_process_handle object instance to be copied from.
214 //------------------------------------------------------------------------------
216  m_target_p(orig.m_target_p)
217 {
218  if ( m_target_p ) m_target_p->reference_increment();
219 }
220 
221 
222 //------------------------------------------------------------------------------
223 //"sc_process_handle::operator ="
224 //
225 // This assignment operator signature is call by value rather than reference.
226 // This means that an sc_process_handle instance will be created and the
227 // target for that instance will be incremented before the assignment is done.
228 // The assignment is done using the swap() method, which simply swaps the
229 // targets of 'orig' and this object instance. We don't need to increment
230 // the reference count for our new target since that was done when 'orig'
231 // was created. Our old target's reference count will be decremented when
232 // 'orig' is deleted.
233 // orig = sc_process_handle object instance to be copied from.
234 // Result is a reference for this object instance.
235 //------------------------------------------------------------------------------
236 inline sc_process_handle&
238 {
239  swap( orig );
240  return *this;
241 }
242 
243 
244 //------------------------------------------------------------------------------
245 //"sc_process_handle::~sc_process_handle"
246 //
247 // This is the object instance destructor for this class. It decrements
248 // the reference count for its target.
249 //------------------------------------------------------------------------------
251 {
252  if ( m_target_p ) m_target_p->reference_decrement();
253 }
254 
255 //------------------------------------------------------------------------------
256 //"sc_process_handle::inline methods"
257 //
258 // These are short inline methods.
259 //------------------------------------------------------------------------------
260 
261 // disable this object instance's target.
262 
264 {
265  if ( m_target_p )
266  m_target_p->disable_process(descendants);
267  else
268  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "disable()");
269 }
270 
271 // call dont_initialize() on this object instance's target.
272 
273 inline void sc_process_handle::dont_initialize( bool dont )
274 {
275  if ( m_target_p )
276  m_target_p->dont_initialize( dont );
277  else
278  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "dont_initialize()");
279 }
280 
281 // dump the status of this object instance's target:
282 
283 inline std::string sc_process_handle::dump_state() const
284 {
285  return m_target_p ? m_target_p->dump_state() : std::string("NO TARGET");
286 }
287 
288 // return whether this object instance's target is dynamic or not.
289 
290 inline bool sc_process_handle::dynamic() const
291 {
292  return m_target_p ? m_target_p->dynamic() : false;
293 }
294 
295 // enable this object instance's target.
296 
298 {
299  if ( m_target_p )
300  m_target_p->enable_process(descendants);
301  else
302  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "enable()");
303 }
304 
305 // return the child objects for this object instance's target.
306 
307 inline
308 const std::vector<sc_event*>& sc_process_handle::get_child_events() const
309 {
311 }
312 
313 // return the child objects for this object instance's target.
314 
315 inline
316 const std::vector<sc_object*>& sc_process_handle::get_child_objects() const
317 {
319 }
320 
321 // return the parent object for this object instance's target.
322 
324 {
325  return m_target_p ? m_target_p->get_parent_object() : NULL;
326 }
327 
328 // return this object instance's target.
329 
331 {
332  return m_target_p;
333 }
334 
335 // return whether this object instance is unwinding or not.
336 
338 {
339  if ( m_target_p )
340  return m_target_p->is_unwinding();
341  else {
342  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "is_unwinding()");
343  return false;
344  }
345 }
346 
347 // kill this object instance's target.
348 
350 {
351  if ( m_target_p )
352  m_target_p->kill_process( descendants );
353  else
354  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "kill()");
355 }
356 
357 // return the name of this object instance's target.
358 
359 inline const char* sc_process_handle::name() const
360 {
361  return m_target_p ? m_target_p->name() : "";
362 }
363 
364 // return the process kind for this object instance's target.
365 
367 {
369 }
370 
371 // reset this object instance's target.
372 
374 {
375  if ( m_target_p )
377  descendants );
378  else
379  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "reset()");
380 }
381 
382 // return the reset event for this object instance's target.
383 
385 {
386  if ( m_target_p )
387  return m_target_p->reset_event();
388  else
389  {
390  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "reset()");
392  }
393 }
394 
395 // resume this object instance's target.
396 
398 {
399  if ( m_target_p )
400  m_target_p->resume_process(descendants);
401  else
402  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "resume()");
403 }
404 
405 // suspend this object instance's target.
406 
408 {
409  if ( m_target_p )
410  m_target_p->suspend_process(descendants);
411  else
412  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "suspend()");
413 }
414 
415 // swap targets of this process handle with the supplied one.
416 
418 {
419  sc_process_b* tmp = m_target_p;
420  m_target_p = other.m_target_p;
421  other.m_target_p = tmp;
422 }
423 
424 // turn sync_reset off for this object instance's target.
425 
427  sc_descendant_inclusion_info descendants)
428 {
429  if ( m_target_p )
431  descendants);
432  else
433  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "sync_reset_off()");
434 }
435 
436 // turn sync_reset on for this object instance's target.
437 
439  sc_descendant_inclusion_info descendants)
440 {
441  if ( m_target_p )
442  {
444  descendants);
445  }
446  else
447  {
448  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "sync_reset_on()");
449  }
450 }
451 
452 // terminate this object instance's target.
453 
454 inline bool sc_process_handle::terminated() const
455 {
456  return m_target_p ? m_target_p->terminated() : false;
457 }
458 
459 // return the termination event for this object instance's target.
460 
462 {
463  if ( m_target_p )
464  return m_target_p->terminated_event();
465  else
466  {
467  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "terminated_event()");
469  }
470 }
471 
472 // return true if this object instance has a target, false it not.
473 
474 inline bool sc_process_handle::valid() const
475 {
476  return m_target_p ? true : false;
477 }
478 
479 //------------------------------------------------------------------------------
480 //"sc_process_handle::sc_throw_it"
481 //
482 // This method throws the supplied exception to the process whose handle this
483 // object instance is, and optionally to the process' descendants. Once the
484 // exception is thrown the currently executed process will suspend to allow
485 // the exception to be propagated. Once the propagation has occurred the
486 // current process will be resumed.
487 //
488 // Notes:
489 // (1) We allocate the helper function on the stack, see the description of
490 // sc_throw_it<EXCEPT>, in sc_process.h, for why.
491 //
492 // Arguments:
493 // exception = exception to be thrown
494 // descendants = indication of whether descendant processes should also
495 // receive the throw.
496 //------------------------------------------------------------------------------
497 template<typename EXCEPT>
498 inline void sc_process_handle::throw_it( const EXCEPT& exception,
499  sc_descendant_inclusion_info descendants)
500 {
501  sc_throw_it<EXCEPT> helper(exception); // helper to throw the exception.
502 
503  if ( !m_target_p )
504  {
505  SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "throw_it()");
506  return;
507  }
508  m_target_p->throw_user(helper, descendants);
509 }
510 
511 
512 //------------------------------------------------------------------------------
513 //"sc_process_b::last_created_process_handle"
514 //
515 // This method returns the kind of this process.
516 //------------------------------------------------------------------------------
518 {
520 }
521 
523 {
525 }
526 
527 } // namespace sc_core
528 
529 // Revision 1.19 2011/08/24 22:05:51 acg
530 // Torsten Maehne: initialization changes to remove warnings.
531 //
532 // Revision 1.18 2011/04/01 22:08:26 acg
533 // Andy Goodrich: remove unused variable.
534 //
535 // Revision 1.17 2011/03/12 21:07:51 acg
536 // Andy Goodrich: changes to kernel generated event support.
537 //
538 // Revision 1.16 2011/02/18 20:27:14 acg
539 // Andy Goodrich: Updated Copyrights.
540 //
541 // Revision 1.15 2011/02/17 19:53:03 acg
542 // Andy Goodrich: changed dump_status() to dump_state() with new signature.
543 //
544 // Revision 1.14 2011/02/13 21:47:37 acg
545 // Andy Goodrich: update copyright notice.
546 //
547 // Revision 1.13 2011/02/13 21:33:30 acg
548 // Andy Goodrich: added dump_status() to allow the dumping of the status
549 // of a process handle's target.
550 //
551 // Revision 1.12 2011/02/01 23:01:53 acg
552 // Andy Goodrich: removed dead code.
553 //
554 // Revision 1.11 2011/02/01 21:07:36 acg
555 // Andy Goodrich: defering of run queue manipulations to the
556 // sc_thread_process::throw_it() method.
557 //
558 // Revision 1.10 2011/01/25 20:50:37 acg
559 // Andy Goodrich: changes for IEEE 1666 2011.
560 //
561 // Revision 1.9 2011/01/20 16:52:20 acg
562 // Andy Goodrich: changes for IEEE 1666 2011.
563 //
564 // Revision 1.8 2011/01/19 23:21:50 acg
565 // Andy Goodrich: changes for IEEE 1666 2011
566 //
567 // Revision 1.7 2011/01/18 20:10:45 acg
568 // Andy Goodrich: changes for IEEE1666_2011 semantics.
569 //
570 // Revision 1.6 2010/07/30 05:21:22 acg
571 // Andy Goodrich: release 2.3 fixes.
572 //
573 // Revision 1.5 2010/07/22 20:02:33 acg
574 // Andy Goodrich: bug fixes.
575 //
576 // Revision 1.4 2009/05/22 16:06:29 acg
577 // Andy Goodrich: process control updates.
578 //
579 // Revision 1.3 2008/05/22 17:06:26 acg
580 // Andy Goodrich: updated copyright notice to include 2008.
581 //
582 // Revision 1.2 2007/09/20 20:32:35 acg
583 // Andy Goodrich: changes to the semantics of throw_it() to match the
584 // specification. A call to throw_it() will immediately suspend the calling
585 // thread until all the throwees have executed. At that point the calling
586 // thread will be restarted before the execution of any other threads.
587 //
588 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
589 // SystemC 2.3
590 //
591 // Revision 1.7 2006/05/08 17:58:24 acg
592 // Andy Goodrich: added David Long's forward declarations for friend
593 // functions, methods, and operators to keep the Microsoft compiler happy.
594 //
595 // Revision 1.6 2006/04/20 17:08:17 acg
596 // Andy Goodrich: 3.0 style process changes.
597 //
598 // Revision 1.5 2006/04/11 23:13:21 acg
599 // Andy Goodrich: Changes for reduced reset support that only includes
600 // sc_cthread, but has preliminary hooks for expanding to method and thread
601 // processes also.
602 //
603 // Revision 1.4 2006/01/24 20:49:05 acg
604 // Andy Goodrich: changes to remove the use of deprecated features within the
605 // simulator, and to issue warning messages when deprecated features are used.
606 //
607 // Revision 1.3 2006/01/13 18:44:30 acg
608 // Added $Log to record CVS changes into the source.
609 
610 #endif // !defined(sc_spawn_h_INCLUDED)
virtual void suspend_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
static std::vector< sc_event * > empty_event_vector
const std::vector< sc_object * > & get_child_objects() const
void reset(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_event & reset_event() const
#define DCAST
Definition: sc_iostream.h:61
void throw_it(const EXCEPT &exception, sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_descendant_inclusion_info
Definition: sc_process.h:136
This class provides access to an sc_process_b object instance in a manner which allows some persisten...
bool operator!=(const sc_process_handle &left, const sc_process_handle &right)
void sync_reset_off(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_event & reset_event()
virtual void disable_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
virtual void kill_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
void reset_process(reset_type rt, sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
friend bool operator!=(const this_type &left, const this_type &right)
class sc_cthread_process * sc_cthread_handle
Definition: sc_process.h:119
bool dont_initialize() const
Definition: sc_process.h:741
std::string dump_state() const
const char * name() const
Definition: sc_object.h:71
void sync_reset_on(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
class sc_method_process * sc_method_handle
Definition: sc_process.h:120
virtual const std::vector< sc_event * > & get_child_events() const
Definition: sc_object.h:108
sc_curr_proc_kind proc_kind() const
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report.h:209
std::string dump_state() const
bool dynamic() const
Definition: sc_process.h:828
void disable(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_process_handle sc_get_last_created_process_handle()
User initiated dynamic process support.
Definition: sc_process.h:558
void suspend(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
Arbitrary exception class.
Definition: sc_process.h:278
sc_object * get_parent_object() const
void resume(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_event & terminated_event()
sc_curr_proc_kind proc_kind() const
Definition: sc_process.h:1120
static std::vector< sc_object * > empty_object_vector
static sc_process_b * m_last_created_process_p
Definition: sc_process.h:957
sc_curr_proc_kind
Definition: sc_process.h:126
friend class sc_process_handle
Definition: sc_process.h:564
friend bool operator<(const this_type &left, const this_type &right)
class sc_thread_process * sc_thread_handle
Definition: sc_process.h:121
bool is_unwinding() const
Definition: sc_process.h:1057
virtual void enable_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
bool operator<(const sc_process_handle &left, const sc_process_handle &right)
static sc_process_handle last_created_process_handle()
bool operator==(const sc_process_handle &left, const sc_process_handle &right)
The event class.
Definition: sc_event.h:260
friend bool operator==(const this_type &left, const this_type &right)
void swap(sc_process_handle &other)
const std::vector< sc_event * > & get_child_events() const
virtual void throw_user(const sc_throw_it_helper &helper, sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
Base class for all structural entities.
Definition: sc_module.h:83
const char * name() const
sc_object * get_parent_object() const
Definition: sc_object.h:115
Base class for all hierarchical channels.
Definition: sc_module.h:712
sc_process_handle & operator=(sc_process_handle src)
void kill(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_object * get_process_object() const
virtual bool terminated() const
Definition: sc_process.h:1210
void enable(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
const ::std::vector< sc_object * > & get_child_objects() const
Definition: sc_process.h:1008
virtual void resume_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:51