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