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