SSim C++ API documentation (v. 1.7.6)
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 <[email protected]>
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 #if TPROCESS_IMPL != 0
33 
34 #if TPROCESS_IMPL==1
35 #include <ucontext.h>
36 #else
37 #include <setjmp.h>
38 #endif
39 
40 #include <siena/ssim.h>
41 
47 namespace ssim {
48 
64 class TProcess : public Process {
65 public:
70  TProcess();
71 
73  TProcess(unsigned long stacksize);
74 
75  virtual ~TProcess();
76 
86  virtual void main() = 0;
87 
93  static unsigned long DefaultStackSize;
94 
100  class Timeout : public Event { };
101 
144  static const Event * wait_for_event(Time timeout = INIT_TIME);
145 
146 private:
147  virtual void init(void);
148  virtual void process_event(const Event * msg);
149  virtual void stop(void);
150 
151 #if TPROCESS_IMPL==1
152  ucontext_t running_ctx;
153 #else
154  jmp_buf running_ctx;
155 #endif
156  char * mystack;
157  unsigned long mystack_size;
158 
159  const Event * ev;
160 
161 #if TPROCESS_IMPL==1
162  static void starter();
163 #else
164  static void starter(int);
165 #endif
166  void pause();
167  void resume();
168 };
169 
170 }; // end namespace ssim
171 
172 #endif /* TPROCESS_IMPL!=VOID */
173 
174 #endif /* _ssim_h */
175