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