00001 // -*-C++-*- 00002 // 00003 // This file is part of the Siena Simulator, a simple discrete-event 00004 // simulator used with the Siena project. See 00005 // http://www.cs.colorado.edu/serl/siena/ 00006 // 00007 // Author: Antonio Carzaniga <carzanig@cs.colorado.edu> 00008 // See the file AUTHORS for full details. 00009 // 00010 // Copyright (C) 2003-2004 University of Colorado 00011 // 00012 // This program is free software; you can redistribute it and/or 00013 // modify it under the terms of the GNU General Public License 00014 // as published by the Free Software Foundation; either version 2 00015 // of the License, or (at your option) any later version. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU General Public License 00023 // along with this program; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 00025 // USA, or send email to serl@cs.colorado.edu. 00026 // 00027 // 00028 // $Id: tprocess.h,v 1.2 2004/01/06 17:52:00 carzanig Exp $ 00029 // 00030 #ifndef _tprocess_h 00031 #define _tprocess_h 00032 00033 #include <ucontext.h> 00034 00035 #include <siena/ssim.h> 00036 00042 namespace ssim { 00043 00059 class TProcess : public Process { 00060 public: 00065 TProcess(); 00066 00068 TProcess(unsigned long stacksize); 00069 00070 virtual ~TProcess(); 00071 00081 virtual void main() = 0; 00082 00088 static unsigned long DefaultStackSize; 00089 00095 class Timeout : public Event { }; 00096 00139 static const Event * wait_for_event(Time timeout = INIT_TIME); 00140 00141 private: 00142 virtual void init(void); 00143 virtual void process_event(const Event * msg); 00144 virtual void stop(void); 00145 00146 ucontext_t resume_ctx; 00147 ucontext_t running_ctx; 00148 char * mystack; 00149 unsigned long mystack_size; 00150 00151 const Event * ev; 00152 00153 static void starter(); 00154 void pause(); 00155 void resume(); 00156 }; 00157 00158 }; // end namespace ssim 00159 00160 #endif /* _ssim_h */ 00161