Thread.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 10 14:43:13 CEST 2002  Thread.hpp
00003 
00004                         Thread.hpp -  description
00005                            -------------------
00006     begin                : Mon June 10 2002
00007     copyright            : (C) 2002 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 #ifndef ORO_THREAD_HPP
00039 #define ORO_THREAD_HPP
00040 
00041 // Our own package config headers.
00042 #include "../rtt-config.h"
00043 #include "fosi.h"
00044 
00045 #include "RunnableInterface.hpp"
00046 #include "ThreadInterface.hpp"
00047 #include "Mutex.hpp"
00048 
00049 #include <string>
00050 
00051 namespace RTT
00052 {
00053     class DigitalOutInterface;
00054 
00055     namespace OS
00056     {
00115         class RTT_API Thread: public OS::ThreadInterface
00116         {
00117             friend void* thread_function(void* t);
00118 
00119         public:
00120 
00131             Thread(int scheduler, int priority, double period,
00132                     const std::string & name,
00133                     OS::RunnableInterface* r = 0);
00134 
00135             virtual ~Thread();
00136 
00144             static void setStackSize(unsigned int ssize);
00145 
00146             virtual bool run(OS::RunnableInterface* r);
00147 
00148             virtual bool start();
00149 
00150             virtual bool stop();
00151 
00152             bool setPeriod(Seconds s);
00153 
00158             bool setPeriod(secs s, nsecs ns);
00159 
00163             bool setPeriod(TIME_SPEC p);
00164 
00169             void getPeriod(secs& s, nsecs& ns) const;
00170 
00171             virtual Seconds getPeriod() const;
00172 
00173             virtual nsecs getPeriodNS() const;
00174 
00175             virtual bool isPeriodic() const;
00176 
00177             virtual bool isRunning() const;
00178 
00179             virtual bool isActive() const;
00180 
00181             virtual const char* getName() const;
00182 
00183             virtual RTOS_TASK * getTask()
00184             {
00185                 return &rtos_task;
00186             }
00187 
00188             virtual bool setScheduler(int sched_type);
00189 
00190             virtual int getScheduler() const;
00191 
00192             virtual bool setPriority(int priority);
00193 
00194             virtual int getPriority() const;
00195 
00196             virtual void yield();
00197 
00198             void setMaxOverrun(int m);
00199 
00200             int getMaxOverrun() const;
00201         protected:
00207             void terminate();
00208 
00209             void emergencyStop();
00210 
00214             virtual void step();
00215 
00219             virtual void loop();
00220 
00224             virtual bool breakLoop();
00225 
00229             virtual bool initialize();
00230 
00234             virtual void finalize();
00235         private:
00236             Thread(const Thread&);
00237 
00238             void setup(int _priority, const std::string& name);
00239 
00243             void configure();
00244 
00245             static unsigned int default_stack_size;
00246 
00250             int msched_type;
00251 
00256             bool active;
00257 
00261             bool prepareForExit;
00262 
00266             bool inloop;
00267 
00271             bool running;
00272 
00276             RTOS_TASK rtos_task;
00277 
00281             rt_sem_t sem;
00282 
00287             rt_sem_t confDone;
00288 
00292             OS::RunnableInterface* runComp;
00293 
00297             MutexRecursive breaker;
00298 
00303             int maxOverRun;
00304 
00308             NANO_TIME period;
00309 
00310 #ifdef OROPKG_OS_THREAD_SCOPE
00311             // Pointer to Threadscope device
00312             DigitalOutInterface * d;
00313 #endif
00314         };
00315 
00316     }
00317 }
00318 
00319 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3