SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_process.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.h -- Process base class support.
21 
22  Original Author: Andy Goodrich, Forte Design Systems, 04 August 2005
23 
24 
25  CHANGE LOG AT THE END OF THE FILE
26  *****************************************************************************/
27 
28 
29 #if !defined(sc_process_h_INCLUDED)
30 #define sc_process_h_INCLUDED
31 
32 #include <string>
33 #include <cassert>
34 #include "sysc/utils/sc_iostream.h"
36 #include "sysc/kernel/sc_object.h"
39 
40 #include <list> // 02/13/2015 GL
41 #include <set>
42 #include <unordered_set>
43 #ifndef SC_INCLUDE_WINDOWS_H // 02/20/2015 GL
44 # define SC_INCLUDE_WINDOWS_H // include Windows.h, if needed
45 #endif
46 #include "sysc/kernel/sc_cmnhdr.h"
47 
48 #if defined(WIN32) || defined(_WIN32)
49 
50 #define CHNL_MTX_TYPE_ CRITICAL_SECTION
51 
52 #define CHNL_MTX_INIT_( Mutex ) \
53  InitializeCriticalSection( &(Mutex) )
54 #define CHNL_MTX_LOCK_( Mutex ) \
55  EnterCriticalSection( &(Mutex) )
56 #define CHNL_MTX_UNLOCK_( Mutex ) \
57  LeaveCriticalSection( &(Mutex) )
58 #define CHNL_MTX_TRYLOCK_( Mutex ) \
59  ( TryEnterCriticalSection( &(Mutex) ) != 0 )
60 #define CHNL_MTX_DESTROY_( Mutex ) \
61  DeleteCriticalSection( &(Mutex) )
62 
63 #else // use pthread mutex
64 
65 #include <pthread.h>
66 #define CHNL_MTX_TYPE_ pthread_mutex_t
67 
68 #if defined(__hpux)
69 # define CHNL_PTHREAD_NULL_ cma_c_null
70 #else // !defined(__hpux)
71 # define CHNL_PTHREAD_NULL_ NULL
72 #endif
73 
74 #define CHNL_MTX_INIT_( Mutex ) \
75  pthread_mutex_init( &(Mutex), CHNL_PTHREAD_NULL_ )
76 #define CHNL_MTX_LOCK_( Mutex ) \
77  pthread_mutex_lock( &(Mutex) )
78 #define CHNL_MTX_UNLOCK_( Mutex ) \
79  pthread_mutex_unlock( &(Mutex) )
80 
81 #ifdef _XOPEN_SOURCE
82 # define CHNL_MTX_TRYLOCK_( Mutex ) \
83  ( pthread_mutex_trylock( &(Mutex) ) == 0 )
84 #else // no try_lock available
85 # define CHNL_MTX_TRYLOCK_( Mutex ) \
86  ( false )
87 #endif
88 
89 #define CHNL_MTX_DESTROY_( Mutex ) \
90  pthread_mutex_destroy( &(Mutex) )
91 
92 #endif
93 
94 #include "sysc/kernel/sc_time.h" // 08/12/2015 GL: to include sc_time type
95 
96 // 08/19/2015 GL: to include sc_dt::uint64
98 // 02/22/2016 ZC: to enable verbose display or not
99 #ifndef _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR
100 #define _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR "SYSC_PRINT_VERBOSE_MESSAGE"
101 #endif
102 namespace sc_core {
103 
104 // Forward declarations:
105 class sc_process_handle;
106 class sc_thread_process;
107 class sc_reset;
108 
109 const char* sc_gen_unique_name( const char*, bool preserve_first );
110 sc_process_handle sc_get_current_process_handle();
111 void sc_thread_cor_fn( void* arg );
112 bool timed_out( sc_simcontext* );
113 
114 extern bool sc_allow_process_control_corners; // see sc_simcontext.cpp.
115 
116 
117 // Process handles as forward references:
118 
122 
123 
124 // Standard process types:
125 
127 {
132 };
133 
134 // Descendant information for process hierarchy operations:
135 
140 };
141 
142 /**************************************************************************/
150 {
151  public:
153  virtual ~sc_process_host() { } // Needed for cast check for sc_module.
154  void defunct() {}
155 };
156 
157 
158 /**************************************************************************/
169  public:
170  enum {
172  };
173  virtual ~sc_process_monitor() {}
174  virtual void signal(sc_thread_handle thread_p, int type);
175  //DM 05/24/2019 sc_method is same as sc_thread
176  virtual void signal(sc_method_handle thread_p, int type);
177 
178 };
181 
182 /**************************************************************************/
199 #if defined(_MSC_VER)
200 #if ( _MSC_VER > 1200 )
201 # define SC_USE_MEMBER_FUNC_PTR
202 #endif
203 #else
204 # define SC_USE_MEMBER_FUNC_PTR
205 #endif
206 
207 
208 // COMPILER DOES SUPPORT CAST TO void (sc_process_host::*)() from (T::*)():
209 
210 #if defined(SC_USE_MEMBER_FUNC_PTR)
211 
212  typedef void (sc_process_host::*SC_ENTRY_FUNC)();
213 # define SC_DECL_HELPER_STRUCT(callback_tag, func) /*EMPTY*/
214 # define SC_MAKE_FUNC_PTR(callback_tag, func) \
215  static_cast<sc_core::SC_ENTRY_FUNC>(&callback_tag::func)
216 
217 
218 // COMPILER NOT DOES SUPPORT CAST TO void (sc_process_host::*)() from (T::*)():
219 
220 #else // !defined(SC_USE_MEMBER_FUNC_PTR)
221  class sc_process_call_base {
222  public:
223  inline sc_process_call_base()
224  {
225  }
226 
227  virtual ~sc_process_call_base()
228  {
229  }
230 
231  virtual void invoke(sc_process_host* host_p)
232  {
233  }
234  };
235  extern sc_process_call_base sc_process_defunct;
236 
237  template<class T>
238  class sc_process_call : public sc_process_call_base {
239  public:
240  sc_process_call( void (T::*method_p)() ) :
241  sc_process_call_base()
242  {
243  m_method_p = method_p;
244  }
245 
246  virtual ~sc_process_call()
247  {
248  }
249 
250  virtual void invoke(sc_process_host* host_p)
251  {
252  (((T*)host_p)->*m_method_p)();
253  }
254 
255  protected:
256  void (T::*m_method_p)(); // Method implementing the process.
257  };
258 
259  typedef sc_process_call_base* SC_ENTRY_FUNC;
260 # define SC_DECL_HELPER_STRUCT(callback_tag, func) /*EMPTY*/
261 # define SC_MAKE_FUNC_PTR(callback_tag, func) \
262  (::sc_core::SC_ENTRY_FUNC) (new \
263  ::sc_core::sc_process_call<callback_tag>(&callback_tag::func))
264 
265 #endif // !defined(SC_USE_MEMBER_FUNC_PTR)
266 
267 
268 extern void sc_set_stack_size( sc_thread_handle, std::size_t );
269 
270 // 04/03/2015 GL: set the stack size of SC_METHODs
271 extern void sc_set_stack_size( sc_method_handle, std::size_t );
272 
273 class sc_event;
274 class sc_event_list;
275 class sc_event_or_list;
276 class sc_name_gen;
277 class sc_spawn_options;
278 class sc_unwind_exception;
279 
280 /**************************************************************************/
303  public:
304  virtual sc_throw_it_helper* clone() const = 0;
305  virtual void throw_it() = 0;
307  virtual ~sc_throw_it_helper() {}
308 };
309 
310 template<typename EXCEPT>
312 {
314  public:
315  sc_throw_it( const EXCEPT& value ) : m_value(value) { }
316  virtual ~sc_throw_it() {}
317  virtual inline this_type* clone() const { return new this_type(m_value); }
318  virtual inline void throw_it() { throw m_value; }
319  protected:
320  EXCEPT m_value; // value to be thrown.
321 };
322 
323 /**************************************************************************/
354 // 02/13/2015 GL.
358 struct sc_chnl_lock {
363 
367  unsigned int counter;
368 
373 };
374 
376  public:
389  void lock_and_push( CHNL_MTX_TYPE_ *lock );
390 
401  void pop_and_unlock( CHNL_MTX_TYPE_ *lock );
402 
408  void lock_all( void );
409 
415  void unlock_all( void );
416 
417  private:
421  std::list<sc_chnl_lock*> queue;
422 };
423 
424 /**************************************************************************/
433 // 08/06/2015 GL.
435 {
436 public:
437 
442 
443  // constructors
444 
445  sc_timestamp();
447  sc_timestamp( long long, int );
448  sc_timestamp( const sc_timestamp& );
449 
450  // assignment operator
451 
456 
457  // relational operators
458 
462  bool operator == ( const sc_timestamp& ) const;
463 
467  bool operator != ( const sc_timestamp& ) const;
468 
472  bool operator < ( const sc_timestamp& ) const;
473 
477  bool operator <= ( const sc_timestamp& ) const;
478 
482  bool operator > ( const sc_timestamp& ) const;
483 
487  bool operator >= ( const sc_timestamp& ) const;
488 
489  // arithmetic operator
490 
495 
496  // get member variables
497 
501  const sc_time& get_time_count() const;
502 
506  value_type get_delta_count() const;
507 
511  bool get_infinite() const;
512 
513  void show() const;
514  std::string to_string() const;
519 
524 
525 private:
526 
527 
528 
532  bool m_infinite;
533 };
534 
535 bool heap_cmp(sc_process_b*& s, sc_process_b*& t); //DM 08/15/2019 for event delivery
536 
537 /**************************************************************************/
558 class sc_process_b : public sc_object {
559  friend class Invoker; //DM 05/16/2019
560 
561  friend class sc_simcontext; // Allow static processes to have base.
562  friend class sc_cthread_process; // Child can access parent.
563  friend class sc_method_process; // Child can access parent.
564  friend class sc_process_handle; // Allow handles to modify ref. count.
565  friend class sc_thread_process; // Child can access parent.
566 
567  friend class sc_object;
568  friend class sc_port_base;
569  friend class sc_runnable;
570  friend class sc_sensitive;
571  friend class sc_sensitive_pos;
572  friend class sc_sensitive_neg;
573  friend class sc_module;
574 
575  // 04/07/2015 GL: a new sc_channel class is derived from sc_module
576  friend class sc_channel;
577 
578  friend class sc_report_handler;
579  friend class sc_reset;
580  friend class sc_reset_finder;
581  friend class sc_unwind_exception;
582 
583  friend const char* sc_gen_unique_name( const char*, bool preserve_first );
585  friend void sc_thread_cor_fn( void* arg );
586  friend bool timed_out( sc_simcontext* );
587 
588  friend bool heap_cmp(sc_process_b*&, sc_process_b*&);
589 
590 
591  public:
592 
593 
594  //19:23 2018/7/7 ZC
595  //for both sc_event_and_list and sc_event_or_list
596 
597  /*
598  / if any event in event_list is triggered
599  / initially false;
600  / when the thread wakes up, set it to false again
601  / this is used to set the initial value of wake_up_time_for_event_list,
602  / which is the first event's time
603  */
604 
606 
607  /*
608  / used for both andlist and orlist
609  / 1) for andlist, it is the max value of all the events
610  / 2) for orlist, it is the min value of all the events
611  */
612 
614 
615  //end
616 
617 
623  {
624  this->segment_ids = segment_ids;
625  }
626 
632  {
633  return segment_ids;
634  }
635 
641 
642 
647  void set_upcoming_socket_id(int socket_id)
648  {
649  this->socket_id_ = socket_id;
650  }
651 
657  {
658  return this->socket_id_;
659  }
660 
666 
667 
672  void increase_offset(int offset)
673  {
674  this->seg_offset_ += offset;
675  }
676 
681  void decrease_offset(int offset)
682  {
683  this->seg_offset_ -= offset;
684  }
685 
691  {
692  return this->seg_offset_;
693  }
694 
695 
702  };
703 
705  ps_bit_disabled = 1, // process is disabled.
706  ps_bit_ready_to_run = 2, // process is ready to run.
707  ps_bit_suspended = 4, // process is suspended.
708  ps_bit_zombie = 8, // process is a zombie.
709  ps_normal = 0 // must be zero.
710  };
711 
712  enum reset_type { // types for sc_process_b::reset_process()
713  reset_asynchronous = 0, // asynchronous reset.
714  reset_synchronous_off, // turn off synchronous reset sticky bit.
715  reset_synchronous_on // turn on synchronous reset sticky bit.
716  };
717 
719  {
728  };
729 
730  public:
731  sc_process_b( const char* name_p, bool is_thread, bool free_host,
732  SC_ENTRY_FUNC method_p, sc_process_host* host_p,
733  const sc_spawn_options* opt_p );
734 
735  protected:
736  // may not be deleted manually (called from destroy_process())
737  virtual ~sc_process_b();
738 
739  public:
740  inline int current_state() { return m_state; }
741  bool dont_initialize() const { return m_dont_init; }
742  virtual void dont_initialize( bool dont );
743  std::string dump_state() const;
744  const ::std::vector<sc_object*>& get_child_objects() const;
745  inline sc_curr_proc_kind proc_kind() const;
748 
756  // 02/16/2015 GL.
757  void lock_and_push( CHNL_MTX_TYPE_ *lock );
758 
765  // 02/16/2015 GL.
766  void pop_and_unlock( CHNL_MTX_TYPE_ *lock );
767 
774  // 02/16/2015 GL.
775  void lock_all_channels( void );
776 
783  // 02/16/2015 GL.
784  void unlock_all_channels( void );
785 
789  // 08/12/2015 GL.
790  int get_segment_id();
791 
795  // 08/12/2015 GL.
796  void set_segment_id( int id );
797 
801  // 08/12/2015 GL.
802  const sc_timestamp& get_timestamp();
803 
807  // 08/12/2015 GL.
808  void set_timestamp( const sc_timestamp& ts );
809 
813  // 09/01/2015 GL.
814  int get_instance_id();
815 
819  void set_instance_id( int id );
820 
821  public:
823  void add_sensitivity_event(const sc_event& e);
824  std::string event_names();
825  protected:
826  virtual void add_child_object( sc_object* );
827  void add_static_event( const sc_event& );
828  bool dynamic() const { return m_dynamic_proc; }
829  const char* gen_unique_name( const char* basename_, bool preserve_first );
831  inline bool is_disabled() const;
832  inline bool is_runnable() const;
833  static inline sc_process_b* last_created_process_base();
834  virtual bool remove_child_object( sc_object* );
835  void remove_dynamic_events( bool skip_timeout = false );
836  void remove_static_events();
837  inline void set_last_report( sc_report* last_p )
838  {
839  delete m_last_report_p;
840  m_last_report_p = last_p;
841  }
842  inline bool timed_out() const;
843  void report_error( const char* msgid, const char* msg = "" ) const;
845 
846  protected: // process control methods:
847  virtual void disable_process(
849  void disconnect_process();
850  virtual void enable_process(
852  inline void initially_in_reset( bool async );
853  inline bool is_unwinding() const;
854  inline bool start_unwinding();
855  inline bool clear_unwinding();
856  virtual void kill_process(
858  void reset_changed( bool async, bool asserted );
859  void reset_process( reset_type rt,
861  virtual void resume_process(
863  virtual void suspend_process(
865  virtual void throw_user( const sc_throw_it_helper& helper,
867  virtual void throw_reset( bool async ) = 0;
868  virtual bool terminated() const;
869  void trigger_reset_event();
870 
871  private:
872  void delete_process();
873  inline void reference_decrement();
874  inline void reference_increment();
875 
876  protected:
877  inline void semantics();
878 
879  // debugging stuff:
880 
881  public:
882  const char* file;
883  int lineno;
884  int proc_id;
888  // 03/10/2017 ZC.
889  //const char* process_name; // not needed, use name() to get process name
890  int m_process_state; //0 running 1 ready 2 waiting 3 waitfor time
891  //4 finished 5 paused
893  protected:
894  int m_active_areset_n; // number of aresets active.
895  int m_active_reset_n; // number of resets active.
896  bool m_dont_init; // true: no initialize call.
897  bool m_dynamic_proc; // true: after elaboration.
898  const sc_event* m_event_p; // Dynamic event waiting on.
899 
900  int m_event_count; // number of events.
901  const sc_event_list* m_event_list_p; // event list waiting on.
902  sc_process_b* m_exist_p; // process existence link.
903  bool m_free_host; // free sc_semantic_host_p.
904  bool m_has_reset_signal; // has reset_signal_is.
905  bool m_has_stack; // true is stack present.
906  bool m_is_thread; // true if this is thread.
907  sc_report* m_last_report_p; // last report this process.
908  sc_name_gen* m_name_gen_p; // subprocess name generator
909  sc_curr_proc_kind m_process_kind; // type of process.
910  int m_references_n; // outstanding handles.
911  std::vector<sc_reset*> m_resets; // resets for process.
912  sc_event* m_reset_event_p; // reset event.
913  sc_event* m_resume_event_p; // resume event.
914  sc_process_b* m_runnable_p; // sc_runnable link
915  sc_process_host* m_semantics_host_p; // host for semantics.
916  SC_ENTRY_FUNC m_semantics_method_p; // method for semantics.
917  int m_state; // process state.
918  std::vector<const sc_event*> m_static_events; // static events waiting on.
919  bool m_sticky_reset; // see note 3 above.
920  sc_event* m_term_event_p; // terminated event.
922  process_throw_type m_throw_status; // exception throwing status
923  bool m_timed_out; // true if we timed out.
924  sc_event* m_timeout_event_p; // timeout event.
925  trigger_t m_trigger_type; // type of trigger using.
926  bool m_unwinding; // true if unwinding stack.
927 
931  // 02/16/2015 GL.
933 
937  // 08/12/2015 GL.
939 
943  // 08/12/2015 GL.
945 
949  // 09/01/2015 GL.
951 
952 
954 
955 
956  protected:
957  static sc_process_b* m_last_created_process_p; // Last process created.
958  public:
960 
961  // 05/13/2019 DM
962  public:
963  bool invoker;
965 
966  //DM 08/14/2019
967  private:
968  sc_process_b* PWT_defining_proc; //DM possible wakeup time defining process
969  std::unordered_set<sc_process_b*> proc_defined; //DM 08/17/2019 processes that this proc defines
970  sc_timestamp min_PWT_distance;
971  int prev_seg_id;
972  int get_previous_seg_id();
973  int group_no;
974 
975 };
976 
977 typedef sc_process_b sc_process_b; // For compatibility.
978 
979 
980 //------------------------------------------------------------------------------
981 //"sc_process_b::XXXX_child_YYYYY"
982 //
983 // These methods provide child object support.
984 //------------------------------------------------------------------------------
985 inline void
987 {
988  sc_object::add_child_object( object_p );
989  reference_increment();
990 }
991 
992 
993 
994 inline bool
996 {
997  if ( sc_object::remove_child_object( object_p ) ) {
998  reference_decrement();
999  return true;
1000  }
1001  else
1002  {
1003  return false;
1004  }
1005 }
1006 
1007 inline const ::std::vector<sc_object*>&
1009 {
1010  return m_child_objects;
1011 }
1012 
1013 
1014 //------------------------------------------------------------------------------
1015 //"sc_process_b::initially_in_reset"
1016 //
1017 // This inline method is a callback to indicate that a reset is active at
1018 // start up. This is because the signal will have been initialized before
1019 // a reset linkage for it is set up, so we won't get a reset_changed()
1020 // callback.
1021 // async = true if this an asynchronous reset.
1022 //------------------------------------------------------------------------------
1023 inline void sc_process_b::initially_in_reset( bool async )
1024 {
1025  if ( async )
1027  else
1028  m_active_reset_n++;
1029 }
1030 
1031 //------------------------------------------------------------------------------
1032 //"sc_process_b::is_disabled"
1033 //
1034 // This method returns true if this process is disabled.
1035 //------------------------------------------------------------------------------
1036 inline bool sc_process_b::is_disabled() const
1037 {
1038  return (m_state & ps_bit_disabled) ? true : false;
1039 }
1040 
1041 //------------------------------------------------------------------------------
1042 //"sc_process_b::is_runnable"
1043 //
1044 // This method returns true if this process is runnable. That is indicated
1045 // by a non-zero m_runnable_p field.
1046 //------------------------------------------------------------------------------
1047 inline bool sc_process_b::is_runnable() const
1048 {
1049  return m_runnable_p != 0;
1050 }
1051 
1052 //------------------------------------------------------------------------------
1053 //"sc_process_b::is_unwinding"
1054 //
1055 // This method returns true if this process is unwinding from a kill or reset.
1056 //------------------------------------------------------------------------------
1057 inline bool sc_process_b::is_unwinding() const
1058 {
1059  return m_unwinding;
1060 }
1061 
1062 //------------------------------------------------------------------------------
1063 //"sc_process_b::start_unwinding"
1064 //
1065 // This method flags that this object instance should start unwinding if the
1066 // current throw status requires an unwind.
1067 //
1068 // Result is true if the flag is set, false if the flag is already set.
1069 //------------------------------------------------------------------------------
1071 {
1072  if ( !m_unwinding )
1073  {
1074  switch( m_throw_status )
1075  {
1076  case THROW_KILL:
1077  case THROW_ASYNC_RESET:
1078  case THROW_SYNC_RESET:
1079  m_unwinding = true;
1080  return true;
1081  case THROW_USER:
1082  default:
1083  break;
1084  }
1085  }
1086  return false;
1087 }
1088 
1089 //------------------------------------------------------------------------------
1090 //"sc_process_b::clear_unwinding"
1091 //
1092 // This method clears this object instance's throw status and always returns
1093 // true.
1094 //------------------------------------------------------------------------------
1096 {
1097  m_unwinding = false;
1098  return true;
1099 }
1100 
1101 
1102 //------------------------------------------------------------------------------
1103 //"sc_process_b::last_created_process_base"
1104 //
1105 // This virtual method returns the sc_process_b pointer for the last
1106 // created process. It is only used internally by the simulator.
1107 //------------------------------------------------------------------------------
1109 {
1110  return m_last_created_process_p;
1111 }
1112 
1113 
1114 
1115 //------------------------------------------------------------------------------
1116 //"sc_process_b::proc_kind"
1117 //
1118 // This method returns the kind of this process.
1119 //------------------------------------------------------------------------------
1121 {
1122  return m_process_kind;
1123 }
1124 
1125 
1126 //------------------------------------------------------------------------------
1127 //"sc_process_b::reference_decrement"
1128 //
1129 // This inline method decrements the number of outstanding references to this
1130 // object instance. If the number of references goes to zero, this object
1131 // can be deleted in "sc_process_b::delete_process()".
1132 //------------------------------------------------------------------------------
1133 inline void sc_process_b::reference_decrement()
1134 {
1135  m_references_n--;
1136  if ( m_references_n == 0 ) delete_process();
1137 }
1138 
1139 
1140 //------------------------------------------------------------------------------
1141 //"sc_process_b::reference_increment"
1142 //
1143 // This inline method increments the number of outstanding references to this
1144 // object instance.
1145 //------------------------------------------------------------------------------
1146 inline void sc_process_b::reference_increment()
1147 {
1148  assert(m_references_n != 0);
1149  m_references_n++;
1150 }
1151 
1152 //------------------------------------------------------------------------------
1153 //"sc_process_b::semantics"
1154 //
1155 // This inline method invokes the semantics for this object instance.
1156 // We check to see if we are initially in reset and then invoke the
1157 // process semantics.
1158 //
1159 // Notes:
1160 // (1) For a description of the process reset mechanism see the top of
1161 // the file sc_reset.cpp.
1162 //------------------------------------------------------------------------------
1164 {
1165  scoped_flag( bool& b ) : ref(b){ ref = true; }
1166  ~scoped_flag() { ref = false; }
1167  bool& ref;
1168 };
1170 {
1171 
1172  // within this function, the process has a stack associated
1173 
1174  scoped_flag scoped_stack_flag( m_has_stack );
1175 
1176  assert( m_process_kind != SC_NO_PROC_ );
1177 
1178  // Determine the reset status of this object instance and potentially
1179  // trigger its notify event:
1180 
1181  // See if we need to trigger the notify event:
1182 
1183  if ( m_reset_event_p &&
1184  ( (m_throw_status == THROW_SYNC_RESET) ||
1186  ) {
1188  }
1189 
1190  // Set the new reset status of this object based on the reset counts:
1191 
1194 
1195  // Dispatch the actual semantics for the process:
1196 
1197 # ifndef SC_USE_MEMBER_FUNC_PTR
1199 # else
1201 # endif
1202 }
1203 
1204 
1205 //------------------------------------------------------------------------------
1206 //"sc_process_b::terminated"
1207 //
1208 // This inline method returns true if this object has terminated.
1209 //------------------------------------------------------------------------------
1210 inline bool sc_process_b::terminated() const
1211 {
1212  return (m_state & ps_bit_zombie) != 0;
1213 }
1214 
1215 
1216 //------------------------------------------------------------------------------
1217 //"sc_process_b::timed_out"
1218 //
1219 // This inline method returns true if this object instance timed out.
1220 //------------------------------------------------------------------------------
1221 inline bool sc_process_b::timed_out() const
1222 {
1223  return m_timed_out;
1224 }
1225 
1226 
1227 } // namespace sc_core
1228 
1229 /*****************************************************************************
1230 
1231  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
1232  changes you are making here.
1233 
1234  Name, Affiliation, Date: Andy Goodrich, Forte Design Systems, 12 Aug 05
1235  Description of Modification: This is the rewrite of process support. It
1236  contains some code from the original
1237  sc_process.h by Stan Liao, and the now-defunct
1238  sc_process_b.h by Stan Liao and Martin
1239  Janssen, all of Synopsys, Inc., It also contains
1240  code from the original sc_process_b.h by
1241  Andy Goodrich of Forte Design Systems and
1242  Bishnupriya Bhattacharya of Cadence Design
1243  Systems.
1244 
1245  Name, Affiliation, Date:
1246  Description of Modification:
1247 
1248  *****************************************************************************/
1249 
1250 // $Log: sc_process.h,v $
1251 // Revision 1.36 2011/08/26 22:44:30 acg
1252 // Torsten Maehne: eliminate unused argument warning.
1253 //
1254 // Revision 1.35 2011/08/26 20:46:10 acg
1255 // Andy Goodrich: moved the modification log to the end of the file to
1256 // eliminate source line number skew when check-ins are done.
1257 //
1258 // Revision 1.34 2011/08/24 22:05:51 acg
1259 // Torsten Maehne: initialization changes to remove warnings.
1260 //
1261 // Revision 1.33 2011/08/15 16:43:24 acg
1262 // Torsten Maehne: changes to remove unused argument warnings.
1263 //
1264 // Revision 1.32 2011/07/24 11:20:03 acg
1265 // Philipp A. Hartmann: process control error message improvements:
1266 // (1) Downgrade error to warning for re-kills of processes.
1267 // (2) Add process name to process messages.
1268 // (3) drop some superfluous colons in messages.
1269 //
1270 // Revision 1.31 2011/04/13 02:44:26 acg
1271 // Andy Goodrich: added m_unwinding flag in place of THROW_NOW because the
1272 // throw status will be set back to THROW_*_RESET if reset is active and
1273 // the check for an unwind being complete was expecting THROW_NONE as the
1274 // clearing of THROW_NOW.
1275 //
1276 // Revision 1.30 2011/04/11 22:07:27 acg
1277 // Andy Goodrich: check for reset event notification before resetting the
1278 // throw_status value.
1279 //
1280 // Revision 1.29 2011/04/10 22:17:36 acg
1281 // Andy Goodrich: added trigger_reset_event() to allow sc_process.h to
1282 // contain the run_process() inline method. sc_process.h cannot have
1283 // sc_simcontext information because of recursive includes.
1284 //
1285 // Revision 1.28 2011/04/08 22:34:06 acg
1286 // Andy Goodrich: moved the semantics() method to this file and made it
1287 // an inline method. Added reset processing to the semantics() method.
1288 //
1289 // Revision 1.27 2011/04/08 18:24:48 acg
1290 // Andy Goodrich: moved reset_changed() to .cpp since it needs visibility
1291 // to sc_simcontext.
1292 //
1293 // Revision 1.26 2011/04/01 21:24:57 acg
1294 // Andy Goodrich: removed unused code.
1295 //
1296 // Revision 1.25 2011/03/28 13:02:51 acg
1297 // Andy Goodrich: Changes for disable() interactions.
1298 //
1299 // Revision 1.24 2011/03/20 13:43:23 acg
1300 // Andy Goodrich: added async_signal_is() plus suspend() as a corner case.
1301 //
1302 // Revision 1.23 2011/03/12 21:07:51 acg
1303 // Andy Goodrich: changes to kernel generated event support.
1304 //
1305 // Revision 1.22 2011/03/08 20:49:31 acg
1306 // Andy Goodrich: implement coarse checking for synchronous reset - suspend
1307 // interaction.
1308 //
1309 // Revision 1.21 2011/03/07 17:38:43 acg
1310 // Andy Goodrich: tightening up of checks for undefined interaction between
1311 // synchronous reset and suspend.
1312 //
1313 // Revision 1.20 2011/03/06 19:57:11 acg
1314 // Andy Goodrich: refinements for the illegal suspend - synchronous reset
1315 // interaction.
1316 //
1317 // Revision 1.19 2011/03/05 19:44:20 acg
1318 // Andy Goodrich: changes for object and event naming and structures.
1319 //
1320 // Revision 1.18 2011/02/19 08:30:53 acg
1321 // Andy Goodrich: Moved process queueing into trigger_static from
1322 // sc_event::notify.
1323 //
1324 // Revision 1.17 2011/02/18 20:27:14 acg
1325 // Andy Goodrich: Updated Copyrights.
1326 //
1327 // Revision 1.16 2011/02/18 20:10:44 acg
1328 // Philipp A. Hartmann: force return expression to be a bool to keep MSVC
1329 // happy.
1330 //
1331 // Revision 1.15 2011/02/17 19:52:45 acg
1332 // Andy Goodrich:
1333 // (1) Simplified process control usage.
1334 // (2) Changed dump_status() to dump_state() with new signature.
1335 //
1336 // Revision 1.14 2011/02/16 22:37:30 acg
1337 // Andy Goodrich: clean up to remove need for ps_disable_pending.
1338 //
1339 // Revision 1.13 2011/02/13 21:47:37 acg
1340 // Andy Goodrich: update copyright notice.
1341 //
1342 // Revision 1.12 2011/02/13 21:41:34 acg
1343 // Andy Goodrich: get the log messages for the previous check in correct.
1344 //
1345 // Revision 1.11 2011/02/13 21:32:24 acg
1346 // Andy Goodrich: moved sc_process_b::reset_process() implementation
1347 // from header to cpp file . Added dump_status() to print out the status of a
1348 // process.
1349 //
1350 // Revision 1.10 2011/02/11 13:25:24 acg
1351 // Andy Goodrich: Philipp A. Hartmann's changes:
1352 // (1) Removal of SC_CTHREAD method overloads.
1353 // (2) New exception processing code.
1354 //
1355 // Revision 1.9 2011/02/04 15:27:36 acg
1356 // Andy Goodrich: changes for suspend-resume semantics.
1357 //
1358 // Revision 1.8 2011/02/01 21:06:12 acg
1359 // Andy Goodrich: new layout for the process_state enum.
1360 //
1361 // Revision 1.7 2011/01/25 20:50:37 acg
1362 // Andy Goodrich: changes for IEEE 1666 2011.
1363 //
1364 // Revision 1.6 2011/01/19 23:21:50 acg
1365 // Andy Goodrich: changes for IEEE 1666 2011
1366 //
1367 // Revision 1.5 2011/01/18 20:10:45 acg
1368 // Andy Goodrich: changes for IEEE1666_2011 semantics.
1369 //
1370 // Revision 1.4 2010/07/22 20:02:33 acg
1371 // Andy Goodrich: bug fixes.
1372 //
1373 // Revision 1.3 2009/05/22 16:06:29 acg
1374 // Andy Goodrich: process control updates.
1375 //
1376 // Revision 1.2 2008/05/22 17:06:26 acg
1377 // Andy Goodrich: updated copyright notice to include 2008.
1378 //
1379 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
1380 // SystemC 2.3
1381 //
1382 // Revision 1.11 2006/05/08 17:58:10 acg
1383 // Andy Goodrich: added David Long's forward declarations for friend
1384 // functions, methods, and operators to keep the Microsoft compiler happy.
1385 //
1386 // Revision 1.10 2006/04/28 23:29:01 acg
1387 // Andy Goodrich: added an sc_core:: prefix to SC_FUNC_PTR in the
1388 // SC_MAKE_FUNC_PTR macro to allow its transpareuse outside of the sc_core
1389 // namespace.
1390 //
1391 // Revision 1.9 2006/04/28 21:52:57 acg
1392 // Andy Goodrich: changed SC_MAKE_FUNC_PTR to use a static cast to address
1393 // and AIX issue wrt sc_module's inherited classes.
1394 //
1395 // Revision 1.8 2006/04/20 17:08:17 acg
1396 // Andy Goodrich: 3.0 style process changes.
1397 //
1398 // Revision 1.7 2006/04/11 23:13:21 acg
1399 // Andy Goodrich: Changes for reduced reset support that only includes
1400 // sc_cthread, but has preliminary hooks for expanding to method and thread
1401 // processes also.
1402 //
1403 // Revision 1.6 2006/03/13 20:26:50 acg
1404 // Andy Goodrich: Addition of forward class declarations, e.g.,
1405 // sc_reset, to keep gcc 4.x happy.
1406 //
1407 // Revision 1.5 2006/01/31 20:09:10 acg
1408 // Andy Goodrich: added explaination of static vs dynamic waits to
1409 // sc_process_b::trigger_static.
1410 //
1411 // Revision 1.4 2006/01/24 20:49:05 acg
1412 // Andy Goodrich: changes to remove the use of deprecated features within the
1413 // simulator, and to issue warning messages when deprecated features are used.
1414 //
1415 // Revision 1.3 2006/01/13 18:44:30 acg
1416 // Added $Log to record CVS changes into the source.
1417 
1418 #endif // !defined(sc_process_h_INCLUDED)
virtual void suspend_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
void report_immediate_self_notification() const
void set_last_report(sc_report *last_p)
Definition: sc_process.h:837
sc_throw_it_helper * m_throw_helper_p
Definition: sc_process.h:921
sc_event * m_reset_event_p
Definition: sc_process.h:912
virtual void add_child_object(sc_object *object_p)
std::string event_names()
friend class Invoker
Definition: sc_process.h:559
int get_segment_id()
Set the current segment ID of this process.
void pop_and_unlock(CHNL_MTX_TYPE_ *lock)
Release a channel lock or decrement the lock counter.
SC_ENTRY_FUNC m_semantics_method_p
Definition: sc_process.h:916
void lock_all(void)
Acquire all the channel locks in the list.
virtual bool remove_child_object(sc_object *)
Definition: sc_process.h:995
virtual this_type * clone() const
Definition: sc_process.h:317
OR list of events.
Definition: sc_event.h:228
sc_timestamp & operator=(const sc_timestamp &)
Overload assignment operator.
process_throw_type m_throw_status
Definition: sc_process.h:922
sc_report * m_last_report_p
Definition: sc_process.h:907
#define CHNL_MTX_TYPE_
Definition: sc_process.h:66
sc_name_gen * m_name_gen_p
Definition: sc_process.h:908
sc_process_b sc_process_b
Definition: sc_process.h:977
void report_error(const char *msgid, const char *msg="") const
sc_event_or_list * m_sensitivity_events
Definition: sc_process.h:892
A time stamp combining timed cycles and delta cycles.
Definition: sc_process.h:434
const sc_time & get_time_count() const
Get the value of timed cycles.
bool is_disabled() const
Definition: sc_process.h:1036
sc_throw_it(const EXCEPT &value)
Definition: sc_process.h:315
sc_dt::uint64 value_type
The data type of delta cycles.
Definition: sc_process.h:441
bool timed_out(sc_simcontext *)
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...
void add_sensitivity_event(const sc_event &e)
bool sc_allow_process_control_corners
void(sc_process_host::* SC_ENTRY_FUNC)()
Definition: sc_process.h:212
bool operator<=(const sc_timestamp &) const
Overload &lt;= operator.
sc_event & reset_event()
virtual void disable_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
void reset_changed(bool async, bool asserted)
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)
void set_upcoming_socket_id(int socket_id)
sets the upcoming socket id ZC 10:30 2018/10/31
Definition: sc_process.h:647
sc_event * m_timeout_event_p
Definition: sc_process.h:924
class sc_cthread_process * sc_cthread_handle
Definition: sc_process.h:119
void set_upcoming_segment_ids(int *segment_ids)
sets the upcoming segment ids TS 07/08/17
Definition: sc_process.h:622
int get_instance_id()
Set the instance ID of this process.
bool dont_initialize() const
Definition: sc_process.h:741
Base class for lists of events.
Definition: sc_event.h:126
bool get_infinite() const
Check whether the time stamp is infinite.
value_type m_delta_count
The value of delta cycles.
Definition: sc_process.h:523
class sc_method_process * sc_method_handle
Definition: sc_process.h:120
const sc_event * m_event_p
Definition: sc_process.h:898
void remove_dynamic_events(bool skip_timeout=false)
void sc_thread_cor_fn(void *arg)
std::string dump_state() const
static sc_process_b * last_created_process_base()
Definition: sc_process.h:1108
bool dynamic() const
Definition: sc_process.h:828
uint64 const sc_uint_base int b
Definition: sc_fxval.h:1003
friend const char * sc_gen_unique_name(const char *, bool preserve_first)
User initiated dynamic process support.
Definition: sc_process.h:558
friend class sc_reset_finder
Definition: sc_process.h:580
unsigned int counter
The lock counter.
Definition: sc_process.h:367
sc_process_host * m_semantics_host_p
Definition: sc_process.h:915
Arbitrary exception class.
Definition: sc_process.h:278
void decrease_offset(int offset)
decrease the offset ZC 10:31 2018/10/31
Definition: sc_process.h:681
sc_timestamp operator+(const sc_timestamp &)
Overload + operator.
virtual sc_throw_it_helper * clone() const =0
sc_event & terminated_event()
sc_curr_proc_kind proc_kind() const
Definition: sc_process.h:1120
void show() const
const char * sc_gen_unique_name(const char *, bool preserve_first)
int m_segment_id
The current segment ID of this process.
Definition: sc_process.h:938
Class that manages the ready-to-run queues.
Definition: sc_runnable.h:42
static sc_process_b * m_last_created_process_p
Definition: sc_process.h:957
sc_curr_proc_kind m_process_kind
Definition: sc_process.h:909
std::vector< const sc_event * > m_static_events
Definition: sc_process.h:918
void lock_and_push(CHNL_MTX_TYPE_ *lock)
Acquire a new channel lock or increment the lock counter.
sc_acq_chnl_lock_queue m_acq_chnl_lock_queue
A list of channel locks acquired by this process.
Definition: sc_process.h:932
std::string to_string() const
trigger_t m_trigger_type
Definition: sc_process.h:925
CHNL_MTX_TYPE_ * lock_p
A pointer to the specific channel lock.
Definition: sc_process.h:362
sc_curr_proc_kind
Definition: sc_process.h:126
void lock_all_channels(void)
Acquire all the channel locks.
A list of channel locks acquired by a process.
Definition: sc_process.h:375
class sc_thread_process * sc_thread_handle
Definition: sc_process.h:121
A data structure to keep the state of a channel lock.
Definition: sc_process.h:358
sc_process_b * m_exist_p
Definition: sc_process.h:902
sc_report * get_last_report()
Definition: sc_process.h:830
bool is_unwinding() const
Definition: sc_process.h:1057
virtual void enable_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
sc_timestamp possible_wakeup_time
Definition: sc_process.h:959
static sc_process_handle last_created_process_handle()
const char * file
Definition: sc_process.h:882
int m_instance_id
The instance ID of this process.
Definition: sc_process.h:950
The event class.
Definition: sc_event.h:260
uint64_t uint64
Definition: sc_nbdefs.h:183
sc_event * m_term_event_p
Definition: sc_process.h:920
int * segment_ids
stores the upcoming segment ids TS 07/08/17
Definition: sc_process.h:640
sc_process_handle sc_get_current_process_handle()
sc_time m_time_count
The value of timed cycles.
Definition: sc_process.h:518
bool operator>=(const sc_timestamp &) const
Overload &gt;= operator.
The simulation context.
virtual void add_child_object(sc_object *)
Definition: sc_process.h:986
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
void unlock_all_channels(void)
Release all the channel locks.
Abstract base class for class sc_port_b.
Definition: sc_port.h:69
sc_timestamp m_timestamp
The local time stamp of this process.
Definition: sc_process.h:944
void increase_offset(int offset)
increase the offset ZC 10:30 2018/10/31
Definition: sc_process.h:672
sc_process_b(const char *name_p, bool is_thread, bool free_host, SC_ENTRY_FUNC method_p, sc_process_host *host_p, const sc_spawn_options *opt_p)
friend void sc_thread_cor_fn(void *arg)
bool operator>(const sc_timestamp &) const
Overload &gt; operator.
friend bool heap_cmp(sc_process_b *&, sc_process_b *&)
Base class for all hierarchical channels.
Definition: sc_module.h:712
virtual void throw_it()=0
bool operator==(const sc_timestamp &) const
Overload == operator.
const char * gen_unique_name(const char *basename_, bool preserve_first)
void lock_and_push(CHNL_MTX_TYPE_ *lock)
Acquire a new channel lock or increment the lock counter.
sc_timestamp wake_up_time_for_event_list
Definition: sc_process.h:613
bool operator<(const sc_timestamp &) const
Overload &lt; operator.
std::vector< sc_reset * > m_resets
Definition: sc_process.h:911
void set_timestamp(const sc_timestamp &ts)
Get the local time stamp of this process.
void sc_set_stack_size(sc_method_handle, std::size_t)
bool operator!=(const sc_timestamp &) const
Overload != operator.
void add_static_event(const sc_event &)
sc_event * m_resume_event_p
Definition: sc_process.h:913
sc_chnl_lock(CHNL_MTX_TYPE_ *m)
The constructor initializes the lock pointer and counter.
Definition: sc_process.h:372
This is the base class for objects which may have processes defined for their methods (e...
Definition: sc_process.h:149
sc_process_b * cur_invoker_method_handle
Definition: sc_process.h:964
int socket_id_
stores the upcoming socket id ZC 10:31 2018/10/31
Definition: sc_process.h:665
void set_instance_id(int id)
Get the instance ID of this process.
sc_clock period is zero sc_clock low time is zero sc_fifo< T > cannot have more than one writer bind interface to port failed complete binding failed remove port failed insert primitive channel failed sc_signal< T > cannot have more than one driver resolved port not bound to resolved signal sc_semaphore requires an initial value
virtual bool terminated() const
Definition: sc_process.h:1210
sc_process_b * m_runnable_p
Definition: sc_process.h:914
virtual void throw_reset(bool async)=0
int get_upcoming_socket_id()
returns the upcoming socket id ZC 10:31 2018/10/31
Definition: sc_process.h:656
bool heap_cmp(sc_process_b *&s, sc_process_b *&t)
const sc_timestamp & get_timestamp()
Set the local time stamp of this process.
friend sc_process_handle sc_get_current_process_handle()
const ::std::vector< sc_object * > & get_child_objects() const
Definition: sc_process.h:1008
value_type get_delta_count() const
Get the value of delta cycles.
int * get_upcoming_segment_ids()
returns the upcoming segment ids TS 07/08/17
Definition: sc_process.h:631
virtual void throw_it()
Definition: sc_process.h:318
virtual void resume_process(sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS)=0
bool is_runnable() const
Definition: sc_process.h:1047
bool event_list_member_triggered
Definition: sc_process.h:605
bool timed_out() const
Definition: sc_process.h:1221
void unlock_all(void)
Release all the channel locks in the list.
virtual void signal(sc_thread_handle thread_p, int type)
Definition: sc_process.h:179
virtual ~sc_throw_it()
Definition: sc_process.h:316
void set_segment_id(int id)
Get the current segment ID of this process.
void pop_and_unlock(CHNL_MTX_TYPE_ *lock)
Release a channel lock or decrement the lock counter.
virtual bool remove_child_object(sc_object *object_p)
int m_process_state
The name of this process.
Definition: sc_process.h:890
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:51
int get_offset()
returns the offset ZC 10:31 2018/10/31
Definition: sc_process.h:690
void initially_in_reset(bool async)
Definition: sc_process.h:1023
const sc_event_list * m_event_list_p
Definition: sc_process.h:901