SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_cor_pthread.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_cor_pthread.h -- Coroutine implementation with pthreads.
23 */
34 #ifndef SC_COR_PTHREAD_H
35 #define SC_COR_PTHREAD_H
36 
37 
38 #if defined(SC_USE_PTHREADS)
39 
40 #include "sysc/kernel/sc_cor.h"
41 #include "sysc/kernel/sc_cmnhdr.h"
42 #include <pthread.h>
43 
44 namespace sc_core {
45 
46 class sc_cor_pkg_pthread;
47 typedef sc_cor_pkg_pthread sc_cor_pkg_t;
48 
61 class sc_cor_pthread : public sc_cor
62 {
63  public:
64 
65  // constructor
66  sc_cor_pthread();
67 
68  // destructor
69  virtual ~sc_cor_pthread();
70 
71  // module method invocator (starts thread execution)
72  static void* invoke_module_method( void* context_p );
73 
74  public:
75  static sc_cor_pthread* m_active_cor_p; // Active coroutine.
76 
77  public:
78  sc_cor_fn* m_cor_fn; // Core function.
79  void* m_cor_fn_arg; // Core function argument.
80  pthread_mutex_t m_mutex; // Mutex to suspend thread on.
81  sc_cor_pkg_pthread* m_pkg_p; // the creating coroutine package
82  pthread_cond_t m_pt_condition; // Condition waiting for.
83  pthread_t m_thread; // Our pthread storage.
84 
85 private:
86 
87  // disabled
88  sc_cor_pthread( const sc_cor_pthread& );
89  sc_cor_pthread& operator = ( const sc_cor_pthread& );
90 };
91 
92 
99 class sc_cor_pkg_pthread
100 : public sc_cor_pkg
101 {
102 public:
103 
104  // constructor
105  sc_cor_pkg_pthread( sc_simcontext* simc );
106 
107  // destructor
108  virtual ~sc_cor_pkg_pthread();
109 
110  // create a new coroutine
111  virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg );
112 
113  // yield to the next coroutine
114  virtual void yield( sc_cor* next_cor );
115 
116  // abort the current coroutine (and resume the next coroutine)
117  virtual void abort( sc_cor* next_cor );
118 
119  // get the main coroutine
120  virtual sc_cor* get_main();
121 
122 private:
123 
124  static int instance_count;
125 
126 private:
127 
128  // disabled
129  sc_cor_pkg_pthread();
130  sc_cor_pkg_pthread( const sc_cor_pkg_pthread& );
131  sc_cor_pkg_pthread& operator = ( const sc_cor_pkg_pthread& );
132 };
133 
134 } // namespace sc_core
135 
136 #endif
137 
138 // $Log: sc_cor_pthread.h,v $
139 // Revision 1.5 2011/08/26 20:46:09 acg
140 // Andy Goodrich: moved the modification log to the end of the file to
141 // eliminate source line number skew when check-ins are done.
142 //
143 // Revision 1.4 2011/02/18 20:27:14 acg
144 // Andy Goodrich: Updated Copyrights.
145 //
146 // Revision 1.3 2011/02/13 21:47:37 acg
147 // Andy Goodrich: update copyright notice.
148 //
149 // Revision 1.2 2008/05/22 17:06:25 acg
150 // Andy Goodrich: updated copyright notice to include 2008.
151 //
152 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
153 // SystemC 2.3
154 //
155 // Revision 1.3 2006/01/13 18:44:29 acg
156 // Added $Log to record CVS changes into the source.
157 //
158 
159 #endif // defined(SC_USE_PTHREADS)
160 
161 // Taf!
Coroutine abstract base classes.
sc_cor_pkg_qt sc_cor_pkg_t
Definition: sc_cor_qt.h:45
void() sc_cor_fn(void *)
Function type for creating coroutines.
Definition: sc_cor.h:52
class SC_API sc_simcontext
Definition: sc_object.h:51