SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_cor.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_cor.h -- Coroutine abstract base classes.
21 
22  Original Author: Martin Janssen, Synopsys, Inc., 2001-12-18
23 
24  CHANGE LOG AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 
28 #ifndef SC_COR_H
29 #define SC_COR_H
30 
31 
32 #include <cassert>
33 #include <cstdlib>
34 
35 //#define SC_LOCK_CHECK // 05/27/2015 GL: check the state of the kernel lock
36 
37 namespace sc_core {
38 
39 class sc_simcontext;
40 
41 
42 /**************************************************************************/
48 typedef void (sc_cor_fn)( void* );
49 
50 
51 /**************************************************************************/
57 class sc_cor
58 {
59 protected:
60 
61  // constructor
62  sc_cor() {}
63 
64 public:
65 
66  // destructor
67  virtual ~sc_cor() {}
68 
69  // switch stack protection on/off
70  virtual void stack_protect( bool /* enable */ ) {}
71 
75  virtual void increment_counter() = 0;
76 
80  virtual void decrement_counter() = 0;
81 
85  virtual unsigned int get_counter() = 0;
86 
87 private:
88 
89  // disabled
90  sc_cor( const sc_cor& );
91  sc_cor& operator = ( const sc_cor& );
92 };
93 
94 
95 /**************************************************************************/
102 {
103 public:
104 
105  // constructor
107  : m_simc( simc ) { assert( simc != 0 ); }
108 
109  // destructor
110  virtual ~sc_cor_pkg() {}
111 
112  // create a new coroutine
113  virtual sc_cor* create(
114  std::size_t stack_size, sc_cor_fn* fn, void* arg ) = 0;
115 
116  // yield to the next coroutine
117  virtual void yield( sc_cor* next_cor ) = 0;
118 
122  virtual void wait( sc_cor* cur_cor ) = 0;
123 
127  virtual void go( sc_cor* next_cor ) = 0;
128 
129  // abort the current coroutine (and resume the next coroutine)
130  virtual void abort( sc_cor* next_cor ) = 0;
131 
132  // join another coroutine
133  virtual void join( sc_cor* join_cor ) = 0;
134 
135  // get the main coroutine
136  virtual sc_cor* get_main() = 0;
137 
141  virtual void acquire_sched_mutex() = 0;
142 
146  virtual void release_sched_mutex() = 0;
147 
151  virtual void set_thread_specific( void* process_b ) = 0;
152 
156  virtual void* get_thread_specific() = 0;
157 
161  virtual bool is_locked() = 0;
162 
166  virtual bool is_unlocked() = 0;
167 
171  virtual bool is_lock_owner() = 0;
172 
176  virtual bool is_not_owner() = 0;
177 
182  virtual bool is_locked_and_owner() = 0;
183 
184  // get the simulation context
186  { return m_simc; }
187 
188 private:
189 
190  sc_simcontext* m_simc;
191 
192 private:
193 
194  // disabled
195  sc_cor_pkg();
196  sc_cor_pkg( const sc_cor_pkg& );
197  sc_cor_pkg& operator = ( const sc_cor_pkg& );
198 };
199 
200 } // namespace sc_core
201 
202 // $Log: sc_cor.h,v $
203 // Revision 1.7 2011/08/26 20:46:09 acg
204 // Andy Goodrich: moved the modification log to the end of the file to
205 // eliminate source line number skew when check-ins are done.
206 //
207 // Revision 1.6 2011/08/15 16:43:24 acg
208 // Torsten Maehne: changes to remove unused argument warnings.
209 //
210 // Revision 1.5 2011/02/18 20:27:14 acg
211 // Andy Goodrich: Updated Copyrights.
212 //
213 // Revision 1.4 2011/02/13 21:47:37 acg
214 // Andy Goodrich: update copyright notice.
215 //
216 // Revision 1.3 2011/01/19 23:21:49 acg
217 // Andy Goodrich: changes for IEEE 1666 2011
218 //
219 // Revision 1.2 2008/05/22 17:06:24 acg
220 // Andy Goodrich: updated copyright notice to include 2008.
221 //
222 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
223 // SystemC 2.3
224 //
225 // Revision 1.3 2006/01/13 18:44:29 acg
226 // Added $Log to record CVS changes into the source.
227 //
228 
229 #endif
230 
231 // Taf!
virtual void increment_counter()=0
Increment the lock counter.
virtual sc_cor * create(std::size_t stack_size, sc_cor_fn *fn, void *arg)=0
virtual bool is_unlocked()=0
Check whether the kernel lock is released.
sc_cor_pkg(sc_simcontext *simc)
Definition: sc_cor.h:106
virtual void acquire_sched_mutex()=0
Acquire the kernel lock.
virtual bool is_not_owner()=0
Check whether the kernel lock is not owned by this coroutine.
Coroutine package abstract base class.
Definition: sc_cor.h:101
sc_simcontext * simcontext()
Definition: sc_cor.h:185
virtual unsigned int get_counter()=0
Get the value of the lock counter.
virtual sc_cor * get_main()=0
Coroutine abstract base class.
Definition: sc_cor.h:57
virtual void stack_protect(bool)
Definition: sc_cor.h:70
virtual bool is_locked_and_owner()=0
Check whether the kernel lock is acquired and owned by this coroutine.
virtual void * get_thread_specific()=0
Get the thread specific data value.
virtual void join(sc_cor *join_cor)=0
virtual void yield(sc_cor *next_cor)=0
virtual void decrement_counter()=0
Decrement the lock counter.
virtual bool is_lock_owner()=0
Check whether the kernel lock is owned by this coroutine.
virtual bool is_locked()=0
Check whether the kernel lock is acquired.
void( sc_cor_fn)(void *)
Function type for creating coroutines.
Definition: sc_cor.h:48
virtual void release_sched_mutex()=0
Release the kernel lock.
virtual ~sc_cor()
Definition: sc_cor.h:67
The simulation context.
virtual void abort(sc_cor *next_cor)=0
virtual ~sc_cor_pkg()
Definition: sc_cor.h:110
virtual void go(sc_cor *next_cor)=0
Resume the next coroutine.
virtual void set_thread_specific(void *process_b)=0
Set the thread specific data value.
virtual void wait(sc_cor *cur_cor)=0
Suspend the current coroutine.