SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_cor_pthread.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_pthread.h -- Coroutine implementation with pthreads.
21 
22  Original Author: Andy Goodrich, Forte Design Systems, 2002-11-10
23 
24  CHANGE LOG AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 
28 #ifndef SC_COR_PTHREAD_H
29 #define SC_COR_PTHREAD_H
30 
31 
32 #if defined(SC_USE_PTHREADS)
33 
34 #include "sysc/kernel/sc_cor.h"
35 #include "sysc/kernel/sc_cmnhdr.h"
36 #include <pthread.h>
37 
38 namespace sc_core {
39 
40 class sc_cor_pkg_pthread;
41 typedef sc_cor_pkg_pthread sc_cor_pkg_t;
42 
43 /**************************************************************************/
55 class sc_cor_pthread : public sc_cor
56 {
57  public:
58 
59  // constructor
60  sc_cor_pthread();
61 
62  // destructor
63  virtual ~sc_cor_pthread();
64 
65  // module method invocator (starts thread execution)
66  static void* invoke_module_method( void* context_p );
67 
71  virtual void increment_counter();
72 
76  virtual void decrement_counter();
77 
81  virtual unsigned int get_counter();
82 
83  public:
84  // 06/10/2015 GL: obsolete in parallel simulation
85  static sc_cor_pthread* m_active_cor_p; // Active coroutine.
86 
87  public:
88  sc_cor_fn* m_cor_fn; // Core function.
89  void* m_cor_fn_arg; // Core function argument.
90 
91  // 10/21/2014 GL: now we use central mutex to suspend thread
92  pthread_mutex_t m_mutex; // Mutex to suspend thread on.
93 
94  sc_cor_pkg_pthread* m_pkg_p; // the creating coroutine package
95  pthread_cond_t m_pt_condition; // Condition waiting for.
96  pthread_t m_thread; // Our pthread storage.
97 
101  // 05/27/2015 GL.
102  unsigned int m_counter;
103 
104 private:
105 
106  // disabled
107  sc_cor_pthread( const sc_cor_pthread& );
108  sc_cor_pthread& operator = ( const sc_cor_pthread& );
109 };
110 
111 
112 /**************************************************************************/
118 class sc_cor_pkg_pthread
119 : public sc_cor_pkg
120 {
121 public:
122 
123  // constructor
124  sc_cor_pkg_pthread( sc_simcontext* simc );
125 
126  // destructor
127  virtual ~sc_cor_pkg_pthread();
128 
129  // create a new coroutine
130  virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg );
131 
132  // yield to the next coroutine
133  virtual void yield( sc_cor* next_cor );
134 
138  virtual void wait( sc_cor* cur_cor );
139 
143  virtual void go( sc_cor* next_cor );
144 
145  // abort the current coroutine (and resume the next coroutine)
146  virtual void abort( sc_cor* next_cor );
147 
148  // join another coroutine
149  virtual void join( sc_cor* join_cor );
150 
151  // get the main coroutine
152  virtual sc_cor* get_main();
153 
157  virtual void acquire_sched_mutex();
158 
162  virtual void release_sched_mutex();
163 
167  virtual void set_thread_specific( void* process_b );
168 
172  virtual void* get_thread_specific();
173 
177  virtual bool is_locked();
178 
182  virtual bool is_unlocked();
183 
187  virtual bool is_lock_owner();
188 
192  virtual bool is_not_owner();
193 
198  virtual bool is_locked_and_owner();
199 
200 private:
201 
202  static int instance_count;
203 
204 private:
205 
206  // disabled
207  sc_cor_pkg_pthread();
208  sc_cor_pkg_pthread( const sc_cor_pkg_pthread& );
209  sc_cor_pkg_pthread& operator = ( const sc_cor_pkg_pthread& );
210 };
211 
212 } // namespace sc_core
213 
214 #endif
215 
216 // $Log: sc_cor_pthread.h,v $
217 // Revision 1.5 2011/08/26 20:46:09 acg
218 // Andy Goodrich: moved the modification log to the end of the file to
219 // eliminate source line number skew when check-ins are done.
220 //
221 // Revision 1.4 2011/02/18 20:27:14 acg
222 // Andy Goodrich: Updated Copyrights.
223 //
224 // Revision 1.3 2011/02/13 21:47:37 acg
225 // Andy Goodrich: update copyright notice.
226 //
227 // Revision 1.2 2008/05/22 17:06:25 acg
228 // Andy Goodrich: updated copyright notice to include 2008.
229 //
230 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
231 // SystemC 2.3
232 //
233 // Revision 1.3 2006/01/13 18:44:29 acg
234 // Added $Log to record CVS changes into the source.
235 //
236 
237 #endif // defined(SC_USE_PTHREADS)
238 
239 // Taf!
void wait(int, sc_simcontext *)
void( sc_cor_fn)(void *)
Function type for creating coroutines.
Definition: sc_cor.h:48
sc_cor_pkg_qt sc_cor_pkg_t
Definition: sc_cor_qt.h:39