Deleted Added
sdiff udiff text old ( 12953:ddfd5e4643a9 ) new ( 12957:e54f9890363d )
full compact
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_PROCESS_HH__
31#define __SYSTEMC_CORE_PROCESS_HH__
32
33#include <functional>
34
35#include "base/fiber.hh"
36#include "systemc/core/list.hh"
37#include "systemc/core/object.hh"
38#include "systemc/ext/core/sc_event.hh"
39#include "systemc/ext/core/sc_module.hh"
40#include "systemc/ext/core/sc_process_handle.hh"
41
42namespace sc_gem5
43{
44
45class Process : public ::sc_core::sc_object, public ListNode
46{
47 public:
48 virtual ::sc_core::sc_curr_proc_kind procKind() const = 0;
49 bool running() const { return _running; }
50 bool dynamic() const { return _dynamic; }
51 bool isUnwinding() const { return _isUnwinding; }
52 bool terminated() const { return _terminated; }
53
54 void forEachKid(const std::function<void(Process *)> &work);
55
56 bool suspended() const { return _suspended; }
57 bool disabled() const { return _disabled; }
58
59 void suspend(bool inc_kids);
60 void resume(bool inc_kids);
61 void disable(bool inc_kids);
62 void enable(bool inc_kids);
63
64 void kill(bool inc_kids);
65 void reset(bool inc_kids);
66 virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids);
67
68 void injectException(ExceptionWrapperBase &exc);
69 ExceptionWrapperBase *excWrapper;
70
71 void syncResetOn(bool inc_kids);
72 void syncResetOff(bool inc_kids);
73
74 void incref() { refCount++; }
75 void decref() { refCount--; }
76
77 const ::sc_core::sc_event &resetEvent() { return _resetEvent; }
78 const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
79
80 // This should only be called before initialization.
81 void dontInitialize() { popListNode(); }
82
83 void setStackSize(size_t size) { stackSize = size; }
84
85 void run();
86
87 virtual Fiber *fiber() { return Fiber::primaryFiber(); }
88
89 static Process *newest() { return _newest; }
90
91 protected:
92 Process(const char *name, ProcessFuncWrapper *func, bool _dynamic);
93
94 static Process *_newest;
95
96 virtual ~Process() { delete func; }
97
98 ::sc_core::sc_event _resetEvent;
99 ::sc_core::sc_event _terminatedEvent;
100
101 ProcessFuncWrapper *func;
102 sc_core::sc_curr_proc_kind _procKind;
103 bool _running;
104 bool _dynamic;
105 bool _isUnwinding;
106 bool _terminated;
107
108 bool _suspended;
109 bool _disabled;
110
111 bool _syncReset;
112
113 int refCount;
114
115 size_t stackSize;
116};
117
118} // namespace sc_gem5
119
120#endif //__SYSTEMC_CORE_PROCESS_HH__