SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_process_handle.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_process_handle.h -- Process access support.
23
24 Original Author: Andy Goodrich, Forte Design Systems, 17 June 2003
25
26
27 CHANGE LOG AT THE END OF THE FILE
28 *****************************************************************************/
29
30// $Log: sc_process_handle.h,v $
31// Revision 1.21 2011/08/26 21:54:04 acg
32// Torsten Maehne: Simplify use of dynamic_cast<> for initializing m_target.
33//
34// Revision 1.20 2011/08/26 20:46:10 acg
35// Andy Goodrich: moved the modification log to the end of the file to
36// eliminate source line number skew when check-ins are done.
37//
38
39#if !defined(sc_process_handle_h_INCLUDED)
40#define sc_process_handle_h_INCLUDED
41
45
46#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
47#pragma warning(push)
48#pragma warning(disable: 4251) // DLL import for std::vector
49#endif
50
51namespace sc_core {
52
53// forward operator declarations:
54
55class sc_process_handle;
56bool
57operator == ( const sc_process_handle& left, const sc_process_handle& right );
58bool
59operator != ( const sc_process_handle& left, const sc_process_handle& right );
60bool
61operator < ( const sc_process_handle& left, const sc_process_handle& right );
62
63
64
65//=============================================================================
66// CLASS sc_process_handle
67//
68// This class provides access to an sc_process_b object instance in a
69// manner which allows some persistence after the deletion of the actual
70// process.
71//=============================================================================
72class sc_simcontext;
75
76 friend bool operator == ( const this_type& left, const this_type& right );
77 friend bool operator != ( const this_type& left, const this_type& right );
78 friend bool operator < ( const this_type& left, const this_type& right );
79 friend class sc_object;
80 friend class sc_join;
81 friend class sc_module;
82 friend class sc_reset;
83 friend class sc_sensitive;
84 friend class sc_sensitive_pos;
85 friend class sc_sensitive_neg;
86 friend class sc_thread_process;
87
88 public:
89 inline sc_process_handle();
90 inline explicit sc_process_handle( sc_object* object_p );
91 inline explicit sc_process_handle( sc_process_b* process_p );
92 inline sc_process_handle( const sc_process_handle& orig );
93 inline ~sc_process_handle();
94 inline sc_process_handle& operator = ( sc_process_handle src );
95 inline void swap( sc_process_handle& other );
96
97 public:
98 inline void disable(
100 inline bool dynamic() const;
101 inline void enable(
103 inline const std::vector<sc_event*>& get_child_events() const;
104 inline const std::vector<sc_object*>& get_child_objects() const;
105 inline sc_object* get_parent_object() const;
106 inline sc_object* get_process_object() const;
107 inline bool is_unwinding() const;
108 inline void kill(
110 inline const char* name() const;
111 inline const char* basename() const;
112 inline sc_curr_proc_kind proc_kind() const;
113 inline void reset(
115 inline sc_event& reset_event() const;
116 inline void resume(
118 inline void suspend(
120 inline void sync_reset_off(
122 inline void sync_reset_on(
124 inline sc_event& terminated_event();
125 inline bool terminated() const;
126 template<typename EXCEPT>
127 inline void throw_it( const EXCEPT& exception,
129 inline bool valid() const;
130
131 public: // implementation specific methods:
132 inline std::string dump_state() const;
133
134 protected:
135 inline bool dont_initialize() const
136 { return m_target_p ? m_target_p->dont_initialize() : false; }
137 inline void dont_initialize( bool dont );
138
139 public:
140 operator sc_process_b* ()
141 { return m_target_p; }
142 operator sc_cthread_handle ();
143 operator sc_method_handle ();
144 operator sc_thread_handle ();
145
146 protected:
147 sc_process_b* m_target_p; // Target for this object instance.
148
149 protected:
150 static std::vector<sc_event*> empty_event_vector; // If m_target_p == 0.
151 static std::vector<sc_object*> empty_object_vector; // If m_target_p == 0.
152 static sc_event& non_event(); // If m_target_p == 0.
153};
154
155inline bool operator == (
156 const sc_process_handle& left, const sc_process_handle& right )
157{
158 return (left.m_target_p != 0) && (right.m_target_p != 0) &&
159 (left.m_target_p == right.m_target_p);
160}
161
162inline bool operator != (
163 const sc_process_handle& left, const sc_process_handle& right )
164{
165 return (left.m_target_p == 0) || (right.m_target_p == 0) ||
166 (left.m_target_p != right.m_target_p);
167}
168
169inline bool operator < (
170 const sc_process_handle& left, const sc_process_handle& right )
171{
172 return left.m_target_p < right.m_target_p;
173}
174
175//------------------------------------------------------------------------------
176//"sc_process_handle::sc_process_handle - non-pointer constructor"
177//
178// This version of the object instance constructor for this class creates
179// an object instance whose target needs to be supplied via an assignment.
180//------------------------------------------------------------------------------
182{
183}
184
185//------------------------------------------------------------------------------
186//"sc_process_handle::sc_process_handle - pointer constructor"
187//
188// This version of the object instance constructor for this class creates
189// an object instance whose target is the supplied sc_object instance.
190// The supplied sc_object must in fact be an sc_process_b instance.
191// object_p -> sc_object instance this is handle for.
192//------------------------------------------------------------------------------
194 m_target_p(dynamic_cast<sc_process_b*>(object_p))
195{
196 if ( m_target_p ) m_target_p->reference_increment();
197}
198
199//------------------------------------------------------------------------------
200//"sc_process_handle::sc_process_handle - pointer constructor"
201//
202// This version of the object instance constructor for this class creates
203// an object instance whose target is the supplied sc_process_b instance.
204// This saves a dynamic cast compared to the sc_object* case.
205// process_p -> process instance this is handle for.
206//------------------------------------------------------------------------------
208 m_target_p(process_p)
209{
210 if ( m_target_p ) m_target_p->reference_increment();
211}
212
213//------------------------------------------------------------------------------
214//"sc_process_handle::sc_process_handle - copy constructor"
215//
216// This version of the object instance constructor for this class provides
217// the copy constructor for the class. It clones the supplied original
218// handle and increments the references to its target.
219// orig = sc_process_handle object instance to be copied from.
220//------------------------------------------------------------------------------
222 m_target_p(orig.m_target_p)
223{
224 if ( m_target_p ) m_target_p->reference_increment();
225}
226
227
228//------------------------------------------------------------------------------
229//"sc_process_handle::operator ="
230//
231// This assignment operator signature is call by value rather than reference.
232// This means that an sc_process_handle instance will be created and the
233// target for that instance will be incremented before the assignment is done.
234// The assignment is done using the swap() method, which simply swaps the
235// targets of 'orig' and this object instance. We don't need to increment
236// the reference count for our new target since that was done when 'orig'
237// was created. Our old target's reference count will be decremented when
238// 'orig' is deleted.
239// orig = sc_process_handle object instance to be copied from.
240// Result is a reference for this object instance.
241//------------------------------------------------------------------------------
242inline sc_process_handle&
244{
245 swap( orig );
246 return *this;
247}
248
249
250//------------------------------------------------------------------------------
251//"sc_process_handle::~sc_process_handle"
252//
253// This is the object instance destructor for this class. It decrements
254// the reference count for its target.
255//------------------------------------------------------------------------------
257{
258 if ( m_target_p ) m_target_p->reference_decrement();
259}
260
261//------------------------------------------------------------------------------
262//"sc_process_handle::inline methods"
263//
264// These are short inline methods.
265//------------------------------------------------------------------------------
266
267// disable this object instance's target.
268
270{
271 if ( m_target_p )
272 m_target_p->disable_process(descendants);
273 else
275}
276
277// call dont_initialize() on this object instance's target.
278
280{
281 if ( m_target_p )
283 else
284 SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "dont_initialize()");
285}
286
287// dump the status of this object instance's target:
288
289inline std::string sc_process_handle::dump_state() const
290{
291 return m_target_p ? m_target_p->dump_state() : std::string("NO TARGET");
292}
293
294// return whether this object instance's target is dynamic or not.
295
296inline bool sc_process_handle::dynamic() const
297{
298 return m_target_p ? m_target_p->dynamic() : false;
299}
300
301// enable this object instance's target.
302
304{
305 if ( m_target_p )
306 m_target_p->enable_process(descendants);
307 else
309}
310
311// return the child objects for this object instance's target.
312
313inline
314const std::vector<sc_event*>& sc_process_handle::get_child_events() const
315{
317}
318
319// return the child objects for this object instance's target.
320
321inline
322const std::vector<sc_object*>& sc_process_handle::get_child_objects() const
323{
325}
326
327// return the parent object for this object instance's target.
328
330{
331 return m_target_p ? m_target_p->get_parent_object() : NULL;
332}
333
334// return this object instance's target.
335
337{
338 return m_target_p;
339}
340
341// return whether this object instance is unwinding or not.
342
344{
345 if ( m_target_p )
346 return m_target_p->is_unwinding();
347 else {
349 return false;
350 }
351}
352
353// kill this object instance's target.
354
356{
357 if ( m_target_p )
358 m_target_p->kill_process( descendants );
359 else
361}
362
363// return the name of this object instance's target.
364
365inline const char* sc_process_handle::name() const
366{
367 return m_target_p ? m_target_p->name() : "";
368}
369
370// return the basename of this object instance's target.
371
372inline const char* sc_process_handle::basename() const
373{
374 return m_target_p ? m_target_p->basename() : "";
375}
376
377// return the process kind for this object instance's target.
378
380{
382}
383
384// reset this object instance's target.
385
387{
388 if ( m_target_p )
390 descendants );
391 else
393}
394
395// return the reset event for this object instance's target.
396
398{
399 if ( m_target_p )
400 return m_target_p->reset_event();
401 else
402 {
404 return non_event();
405 }
406}
407
408// resume this object instance's target.
409
411{
412 if ( m_target_p )
413 m_target_p->resume_process(descendants);
414 else
416}
417
418// suspend this object instance's target.
419
421{
422 if ( m_target_p )
423 m_target_p->suspend_process(descendants);
424 else
426}
427
428// swap targets of this process handle with the supplied one.
429
431{
433 m_target_p = other.m_target_p;
434 other.m_target_p = tmp;
435}
436
437// turn sync_reset off for this object instance's target.
438
441{
442 if ( m_target_p )
444 descendants);
445 else
447}
448
449// turn sync_reset on for this object instance's target.
450
453{
454 if ( m_target_p )
455 {
457 descendants);
458 }
459 else
460 {
462 }
463}
464
465// terminate this object instance's target.
466
468{
469 return m_target_p ? m_target_p->terminated() : false;
470}
471
472// return the termination event for this object instance's target.
473
475{
476 if ( m_target_p )
478 else
479 {
480 SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "terminated_event()");
481 return non_event();
482 }
483}
484
485// return true if this object instance has a target, false it not.
486
487inline bool sc_process_handle::valid() const
488{
489 return m_target_p ? true : false;
490}
491
492//------------------------------------------------------------------------------
493//"sc_process_handle::sc_throw_it"
494//
495// This method throws the supplied exception to the process whose handle this
496// object instance is, and optionally to the process' descendants. Once the
497// exception is thrown the currently executed process will suspend to allow
498// the exception to be propagated. Once the propagation has occurred the
499// current process will be resumed.
500//
501// Notes:
502// (1) We allocate the helper function on the stack, see the description of
503// sc_throw_it<EXCEPT>, in sc_process.h, for why.
504//
505// Arguments:
506// exception = exception to be thrown
507// descendants = indication of whether descendant processes should also
508// receive the throw.
509//------------------------------------------------------------------------------
510template<typename EXCEPT>
511inline void sc_process_handle::throw_it( const EXCEPT& exception,
513{
514 sc_throw_it<EXCEPT> helper(exception); // helper to throw the exception.
515
516 if ( !m_target_p )
517 {
519 return;
520 }
521 m_target_p->throw_user(helper, descendants);
522}
523
524
525//------------------------------------------------------------------------------
526//"sc_process_b::last_created_process_handle"
527//
528// This method returns the kind of this process.
529//------------------------------------------------------------------------------
531{
533}
534
536{
538}
539
540} // namespace sc_core
541
542#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
543#pragma warning(pop)
544#endif
545
546// Revision 1.19 2011/08/24 22:05:51 acg
547// Torsten Maehne: initialization changes to remove warnings.
548//
549// Revision 1.18 2011/04/01 22:08:26 acg
550// Andy Goodrich: remove unused variable.
551//
552// Revision 1.17 2011/03/12 21:07:51 acg
553// Andy Goodrich: changes to kernel generated event support.
554//
555// Revision 1.16 2011/02/18 20:27:14 acg
556// Andy Goodrich: Updated Copyrights.
557//
558// Revision 1.15 2011/02/17 19:53:03 acg
559// Andy Goodrich: changed dump_status() to dump_state() with new signature.
560//
561// Revision 1.14 2011/02/13 21:47:37 acg
562// Andy Goodrich: update copyright notice.
563//
564// Revision 1.13 2011/02/13 21:33:30 acg
565// Andy Goodrich: added dump_status() to allow the dumping of the status
566// of a process handle's target.
567//
568// Revision 1.12 2011/02/01 23:01:53 acg
569// Andy Goodrich: removed dead code.
570//
571// Revision 1.11 2011/02/01 21:07:36 acg
572// Andy Goodrich: defering of run queue manipulations to the
573// sc_thread_process::throw_it() method.
574//
575// Revision 1.10 2011/01/25 20:50:37 acg
576// Andy Goodrich: changes for IEEE 1666 2011.
577//
578// Revision 1.9 2011/01/20 16:52:20 acg
579// Andy Goodrich: changes for IEEE 1666 2011.
580//
581// Revision 1.8 2011/01/19 23:21:50 acg
582// Andy Goodrich: changes for IEEE 1666 2011
583//
584// Revision 1.7 2011/01/18 20:10:45 acg
585// Andy Goodrich: changes for IEEE1666_2011 semantics.
586//
587// Revision 1.6 2010/07/30 05:21:22 acg
588// Andy Goodrich: release 2.3 fixes.
589//
590// Revision 1.5 2010/07/22 20:02:33 acg
591// Andy Goodrich: bug fixes.
592//
593// Revision 1.4 2009/05/22 16:06:29 acg
594// Andy Goodrich: process control updates.
595//
596// Revision 1.3 2008/05/22 17:06:26 acg
597// Andy Goodrich: updated copyright notice to include 2008.
598//
599// Revision 1.2 2007/09/20 20:32:35 acg
600// Andy Goodrich: changes to the semantics of throw_it() to match the
601// specification. A call to throw_it() will immediately suspend the calling
602// thread until all the throwees have executed. At that point the calling
603// thread will be restarted before the execution of any other threads.
604//
605// Revision 1.1.1.1 2006/12/15 20:20:05 acg
606// SystemC 2.3
607//
608// Revision 1.7 2006/05/08 17:58:24 acg
609// Andy Goodrich: added David Long's forward declarations for friend
610// functions, methods, and operators to keep the Microsoft compiler happy.
611//
612// Revision 1.6 2006/04/20 17:08:17 acg
613// Andy Goodrich: 3.0 style process changes.
614//
615// Revision 1.5 2006/04/11 23:13:21 acg
616// Andy Goodrich: Changes for reduced reset support that only includes
617// sc_cthread, but has preliminary hooks for expanding to method and thread
618// processes also.
619//
620// Revision 1.4 2006/01/24 20:49:05 acg
621// Andy Goodrich: changes to remove the use of deprecated features within the
622// simulator, and to issue warning messages when deprecated features are used.
623//
624// Revision 1.3 2006/01/13 18:44:30 acg
625// Added $Log to record CVS changes into the source.
626
627#endif // !defined(sc_spawn_h_INCLUDED)
#define SC_API
Definition: sc_cmnhdr.h:148
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report.h:213
class sc_cthread_process * sc_cthread_handle
Definition: sc_process.h:60
class SC_API sc_simcontext
Definition: sc_object.h:50
class sc_method_process * sc_method_handle
Definition: sc_process.h:61
bool operator!=(const sc_process_handle &left, const sc_process_handle &right)
sc_process_handle sc_get_last_created_process_handle()
bool operator==(const sc_process_handle &left, const sc_process_handle &right)
const char SC_ID_EMPTY_PROCESS_HANDLE_[]
sc_curr_proc_kind
Definition: sc_process.h:68
@ SC_NO_PROC_
Definition: sc_process.h:69
class sc_thread_process * sc_thread_handle
Definition: sc_process.h:62
bool operator<(const sc_process_handle &left, const sc_process_handle &right)
sc_descendant_inclusion_info
Definition: sc_process.h:77
@ SC_NO_DESCENDANTS
Definition: sc_process.h:78
sc_object * get_parent_object() const
Definition: sc_object.h:255
const char * name() const
Definition: sc_object.h:122
const char * basename() const
virtual const std::vector< sc_object * > & get_child_objects() const
Definition: sc_object.h:220
virtual const std::vector< sc_event * > & get_child_events() const
Definition: sc_object.h:217
bool dynamic() const
Definition: sc_process.h:305
bool dont_initialize() const
Definition: sc_process.h:288
std::string dump_state() const
sc_event & terminated_event()
virtual void resume_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
virtual void enable_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
virtual void kill_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
static sc_process_b * m_last_created_process_p
Definition: sc_process.h:404
friend class sc_process_handle
Definition: sc_process.h:209
virtual bool terminated() const
Definition: sc_process.h:642
void reset_process(reset_type rt, sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
virtual void disable_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
sc_curr_proc_kind proc_kind() const
Definition: sc_process.h:554
virtual void suspend_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
virtual void throw_user(const sc_throw_it_helper &helper, sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
static sc_process_handle last_created_process_handle()
bool is_unwinding() const
Definition: sc_process.h:491
sc_event & reset_event()
sc_object * get_parent_object() const
void disable(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
const std::vector< sc_event * > & get_child_events() const
void enable(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
const char * name() const
static std::vector< sc_event * > empty_event_vector
std::string dump_state() const
static sc_event & non_event()
void kill(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
void suspend(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
const std::vector< sc_object * > & get_child_objects() const
void swap(sc_process_handle &other)
static std::vector< sc_object * > empty_object_vector
sc_event & reset_event() const
void resume(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
const char * basename() const
void throw_it(const EXCEPT &exception, sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
void sync_reset_on(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_process_handle & operator=(sc_process_handle src)
void reset(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_curr_proc_kind proc_kind() const
void sync_reset_off(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)
sc_object * get_process_object() const