Microsimulation API

tprocess.h
Go to the documentation of this file.
1 // -*-C++-*-
2 //
3 // This file is part of SSim, a simple discrete-event simulator.
4 // See http://www.inf.usi.ch/carzaniga/ssim/
5 //
6 // Copyright (C) 2003-2005 University of Colorado
7 // Copyright (C) 2012 Antonio Carzaniga
8 //
9 // Authors: Antonio Carzaniga <firstname.lastname@usi.ch>
10 // See AUTHORS for full details.
11 //
12 // SSim is free software: you can redistribute it and/or modify it under
13 // the terms of the GNU General Public License as published by the Free
14 // Software Foundation, either version 3 of the License, or (at your
15 // option) any later version.
16 //
17 // SSim is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with SSim. If not, see <http://www.gnu.org/licenses/>.
24 //
25 #ifndef _tprocess_h
26 #define _tprocess_h
27
28 #ifndef TPROCESS_IMPL
29 #include <tprocessconf.h>
30 #endif
31
32 // to make OSX happy with using ucontext.h
33 #define _XOPEN_SOURCE
34
35 #if TPROCESS_IMPL != 0
36
37 #if TPROCESS_IMPL==1
38 #include <ucontext.h>
39 #else
40 #include <setjmp.h>
41 #endif
42
43 #include <siena/ssim.h>
44
50 namespace ssim {
51
67 class TProcess : public Process {
68 public:
73 TProcess();
74
76 TProcess(unsigned long stacksize);
77
78 virtual ~TProcess();
79
89 virtual void main() = 0;
90
96 static unsigned long DefaultStackSize;
97
103 class Timeout : public Event { };
104
147 static const Event * wait_for_event(Time timeout = INIT_TIME);
148
149 private:
150 virtual void initialize(void);
151 virtual void process_event(const Event * msg);
152 virtual void stop(void);
153
154 #if TPROCESS_IMPL==1
155 ucontext_t running_ctx;
156 #else
157 jmp_buf running_ctx;
158 #endif
159 char * mystack;
160 unsigned long mystack_size;
161
162 const Event * ev;
163
164 #if TPROCESS_IMPL==1
165 static void starter();
166 #else
167 static void starter(int);
168 #endif
169 void pause();
170 void resume();
171 };
172
173 }; // end namespace ssim
174
175 #endif /* TPROCESS_IMPL!=VOID */
176
177 #endif /* _ssim_h */
178
ssim::Time
double Time
virtual time type
Definition: ssim.h:79
main
int main()
Definition: rngstream-example.cpp:6
tprocessconf.h
ssim::INIT_TIME
const Time INIT_TIME
beginning of time
Definition: ssim.h:83
ssim.h
ssim
name space for the Siena simulator.
Definition: microsimulation.cc:8