BaseThread.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-01-17 22:34:01 -0600 (Mon, 17 Jan 2005) $
00011  * Version:       $Revision: 16635 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_BASE_THREAD_H_
00043 #define _VPR_BASE_THREAD_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 
00047 #include <boost/concept_check.hpp>
00048 #include <vpr/vprTypes.h>
00049 #include <vpr/Thread/TSTable.h>            /* Needed to cache a copy here */
00050 
00051 namespace vpr
00052 {
00053 
00059 typedef void (*thread_func_t)(void *);
00060 
00061 
00062 class BaseThreadFunctor;
00063 
00073 class VPR_CLASS_API BaseThread
00074 {
00075 public:
00076    enum VPRThreadPriority
00077    {
00078       VPR_PRIORITY_LOW,      
00079       VPR_PRIORITY_NORMAL,   
00080       VPR_PRIORITY_HIGH,     
00081       VPR_PRIORITY_URGENT    
00082    };
00083 
00084    enum VPRThreadScope
00085    {
00086       VPR_LOCAL_THREAD,
00087       VPR_GLOBAL_THREAD
00088    };
00089 
00090    enum VPRThreadState
00091    {
00092       VPR_JOINABLE_THREAD,   
00093       VPR_UNJOINABLE_THREAD  
00094    };
00095 
00096    BaseThread() : mThreadId(-1)
00097    {
00098       ;
00099    }
00100 
00101    virtual ~BaseThread()
00102    {
00103       ;
00104    }
00105 
00107    virtual void setFunctor(BaseThreadFunctor* functorPtr) = 0;
00108 
00110    virtual vpr::ReturnStatus start() = 0;
00111 
00112 public:     // Thread specific data caching
00119    TSTable* getTSTable()
00120    {
00121       return &mTSTable;
00122    }
00123 
00128    static TSTable* getGlobalTSTable()
00129    {
00130       return &gTSTable;
00131    }
00132 
00133 private:
00134    TSTable        mTSTable;  
00135    static TSTable gTSTable;  
00139 protected:
00153    void registerThread(bool successfulCreation);
00154 
00155    void unregisterThread();
00156 
00178 /*
00179    virtual vpr::ReturnStatus spawn(BaseThreadFunctor* functorPtr,
00180                                    VPRThreadPriority priority = VPR_PRIORITY_NORMAL,
00181                                    VPRThreadScope scope = VPR_GLOBAL_THREAD,
00182                                    VPRThreadState state = VPR_JOINABLE_THREAD,
00183                                    size_t stack_size = 0)
00184    {
00185       std::cerr << "Base spawn.  Should NOT be called." << std::endl;
00186       return vpr::ReturnStatus::Fail;
00187    }
00188 */
00189 
00190 public:
00204    virtual int join(void** status = 0)
00205    {
00206       boost::ignore_unused_variable_warning(status);
00207       return -1;
00208    }
00209 
00217    virtual int resume()
00218    {
00219       return -1;
00220    }
00221 
00228    virtual int suspend()
00229    {
00230       return -1;
00231    }
00232 
00245    virtual int getPrio(VPRThreadPriority* prio)
00246    {
00247       boost::ignore_unused_variable_warning(prio);
00248       return -1;
00249    }
00250 
00259    virtual int setPrio(VPRThreadPriority prio)
00260    {
00261       boost::ignore_unused_variable_warning(prio);
00262       return -1;
00263    }
00264 
00273    vpr::Int32 getTID()
00274    {
00275       return mThreadId;
00276    }
00277 
00289    bool valid()
00290    {
00291       return (mThreadId != -1);
00292    }
00293 
00304    virtual int kill(int signum)
00305    {
00306       boost::ignore_unused_variable_warning(signum);
00307       return -1;
00308    }
00309 
00315    virtual void kill()
00316    {;}
00317 
00321    virtual std::ostream& outStream(std::ostream& out);
00322 
00323 protected:
00327    void createThreadId()
00328    {
00329       mThreadId = getNextThreadId();
00330    }
00331 
00332 private:
00334    BaseThread(BaseThread&)
00335    {;}
00336 
00337 protected:
00338    vpr::Int32  mThreadId;    
00339 
00340    // --- STATICS ---- //
00341 
00342 private:
00343    // XXX: What happens when it rolls over after we have been running for a
00344    // LONG time.
00345    vpr::Int32 getNextThreadId()
00346    {
00347       return mNextThreadId++;
00348    }
00349 
00350    static vpr::Int32 mNextThreadId;    // Initialized to 0
00351 };
00352 
00354 VPR_API(std::ostream&) operator<<(std::ostream& out, Thread* threadPtr);
00355 
00356 } // End of vpr namespace
00357 
00358 
00359 #endif

Generated on Thu Jan 4 10:52:09 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1