SingleThread.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Apr 22 20:40:53 CEST 2004  SingleThread.hpp 
00003 
00004                         SingleThread.hpp -  description
00005                            -------------------
00006     begin                : Thu April 22 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009  
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/ 
00037  
00038 
00039 #ifndef SINGLE_THREAD_HPP
00040 #define SINGLE_THREAD_HPP
00041 
00042 // Our own package config headers.
00043 #include "../rtt-config.h"
00044 #include "fosi.h"
00045 
00046 #include "RunnableInterface.hpp"
00047 #include "ThreadInterface.hpp"
00048 #include "Mutex.hpp"
00049 
00050 #include <string>
00051 
00052 namespace RTT
00053 { 
00054     class DigitalOutInterface;
00055 
00056     namespace OS {
00084     class SingleThread 
00085         : public OS::ThreadInterface
00086     {
00087         friend void* singleThread_f( void* t );
00088     public:
00097         SingleThread(int priority, const std::string& name, OS::RunnableInterface* r=0);
00098     
00108         SingleThread(int scheduler, int priority, const std::string& name, OS::RunnableInterface* r=0);
00109     
00110         virtual ~SingleThread();
00111 
00112         virtual bool run( OS::RunnableInterface* r);
00113 
00124         virtual bool start();
00125 
00137         virtual bool stop();
00138 
00142         virtual bool isRunning() const;
00143 
00147         virtual bool isActive() const;
00148 
00152         virtual const char* getName() const;
00157         virtual RTOS_TASK * getTask(){return &(this->rtos_task);};
00158 
00159         virtual bool setScheduler(int sched_type);
00160         virtual int getScheduler() const;
00161 
00162         virtual Seconds getPeriod() const { return 0.0; }
00163         virtual nsecs getPeriodNS() const { return 0; }
00164 
00165         virtual bool setPriority(int priority);
00166 
00167         virtual int getPriority() const;
00168 
00169         virtual void yield();
00170 
00171     protected:
00172 
00173         virtual bool breakLoop();
00174 
00175         virtual void loop();
00176     
00177         virtual bool initialize();
00178 
00179         virtual void finalize();
00180 
00181     private:
00182         void setup(int _priority, const std::string& name);
00183 
00187         int msched_type;
00188 
00193         bool active;
00194 
00198         bool prepareForExit;
00199 
00203         bool inloop;
00204 
00208         bool runloop;
00209 
00213         RTOS_TASK rtos_task;
00214 
00218         rt_sem_t sem;
00219 
00224         rt_sem_t confDone;
00225 
00229         OS::RunnableInterface* runComp;
00230 
00234         MutexRecursive breaker;
00235 
00236 #ifdef OROPKG_OS_THREAD_SCOPE
00237     // Pointer to Threadscope device
00238         DigitalOutInterface * d;
00239 #endif    
00240     };
00241 
00242 }}
00243 
00244 #endif

Generated on Tue Aug 25 14:17:23 2009 for Orocos Real-Time Toolkit by  doxygen 1.5.8