SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_cor_fiber.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_fiber.h -- Coroutine implementation with fibers.
23 */
34 #ifndef SC_COR_FIBER_H
35 #define SC_COR_FIBER_H
36 
37 #if defined(_WIN32) || defined(WIN32) || defined(WIN64)
38 
39 #include "sysc/kernel/sc_cor.h"
40 #include "sysc/kernel/sc_cmnhdr.h"
41 
42 #if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__
43  // _Unwind_SjLj_Register() & _Unwind_SjLj_Unregister() only need first field.
44  struct SjLj_Function_Context {
45  struct SjLj_Function_Context *prev;
46  };
47 #endif
48 
49 namespace sc_core {
50 
51 class sc_cor_pkg_fiber;
52 typedef sc_cor_pkg_fiber sc_cor_pkg_t;
53 
54 #if( defined(_MSC_VER) && _MSC_VER >= 1300 )
55 typedef std::size_t size_t;
56 #endif
57 
64 class sc_cor_fiber
65 : public sc_cor
66 {
67 
68 public:
69 
70  // constructor
71  sc_cor_fiber()
72  : m_stack_size( 0 ), m_fiber( 0 ), m_pkg( 0 )
73  {
74 # if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__
75  m_eh.prev = 0;
76 # endif
77  }
78 
79  // destructor
80  virtual ~sc_cor_fiber();
81 
82 public:
83 
84  std::size_t m_stack_size; // stack size
85  void* m_fiber; // fiber
86 
87  sc_cor_pkg_fiber* m_pkg; // the creating coroutine package
88 #if defined(__GNUC__) && __USING_SJLJ_EXCEPTIONS__
89  struct SjLj_Function_Context m_eh; // the exception handling context
90 #endif
91 
92 
93 private:
94 
95  // disabled
96  sc_cor_fiber( const sc_cor_fiber& );
97  sc_cor_fiber& operator = ( const sc_cor_fiber& );
98 };
99 
100 
107 class SC_API sc_cor_pkg_fiber
108 : public sc_cor_pkg
109 {
110  public:
111 
112  // constructor
113  sc_cor_pkg_fiber( sc_simcontext* simc );
114 
115  // destructor
116  virtual ~sc_cor_pkg_fiber();
117 
118  // create a new coroutine
119  virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg );
120 
121  // yield to the next coroutine
122  virtual void yield( sc_cor* next_cor );
123 
124  // abort the current coroutine (and resume the next coroutine)
125  virtual void abort( sc_cor* next_cor );
126 
127  // get the main coroutine
128  virtual sc_cor* get_main();
129 
130 private:
131 
132  static int instance_count;
133 
134 private:
135 
136  // disabled
137  sc_cor_pkg_fiber();
138  sc_cor_pkg_fiber( const sc_cor_pkg_fiber& );
139  sc_cor_pkg_fiber& operator = ( const sc_cor_pkg_fiber& );
140 };
141 
142 } // namespace sc_core
143 
144 #endif // WIN32
145 
146 // $Log: sc_cor_fiber.h,v $
147 // Revision 1.6 2011/08/26 20:46:09 acg
148 // Andy Goodrich: moved the modification log to the end of the file to
149 // eliminate source line number skew when check-ins are done.
150 //
151 // Revision 1.5 2011/06/25 17:08:39 acg
152 // Andy Goodrich: Jerome Cornet's changes to use libtool to build the
153 // library.
154 //
155 // Revision 1.4 2011/02/18 20:27:14 acg
156 // Andy Goodrich: Updated Copyrights.
157 //
158 // Revision 1.3 2011/02/13 21:47:37 acg
159 // Andy Goodrich: update copyright notice.
160 //
161 // Revision 1.2 2008/05/22 17:06:25 acg
162 // Andy Goodrich: updated copyright notice to include 2008.
163 //
164 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
165 // SystemC 2.3
166 //
167 // Revision 1.3 2006/01/13 18:44:29 acg
168 // Added $Log to record CVS changes into the source.
169 //
170 
171 #endif
172 
173 // 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
#define SC_API
Definition: sc_cmnhdr.h:168