PixelLightAPI  .
ThreadImpl.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ThreadImpl.h                                   *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_THREAD_IMPL_H__
00024 #define __PLCORE_THREAD_IMPL_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/PLCore.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 class Thread;
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Classes                                               ]
00048 //[-------------------------------------------------------]
00049 /**
00050 *  @brief
00051 *    Abstract base class for platform specific 'Thread' implementations
00052 *
00053 *  @note
00054 *    - Implementation of the bridge design pattern, this class is the implementor of the 'Thread' abstraction
00055 */
00056 class ThreadImpl {
00057 
00058 
00059     //[-------------------------------------------------------]
00060     //[ Friends                                               ]
00061     //[-------------------------------------------------------]
00062     friend class Thread;
00063 
00064 
00065     //[-------------------------------------------------------]
00066     //[ Protected functions                                   ]
00067     //[-------------------------------------------------------]
00068     protected:
00069         /**
00070         *  @brief
00071         *    Constructor
00072         *
00073         *  @param[in] cThread
00074         *    Reference to the owning thread
00075         */
00076         ThreadImpl(Thread &cThread);
00077 
00078         /**
00079         *  @brief
00080         *    Destructor
00081         */
00082         virtual ~ThreadImpl();
00083 
00084         /**
00085         *  @brief
00086         *    Returns a reference to the owning thread
00087         *
00088         *  @return
00089         *    Reference to the owning thread
00090         */
00091         Thread &GetThread() const;
00092 
00093 
00094     //[-------------------------------------------------------]
00095     //[ Protected virtual ThreadImpl functions                ]
00096     //[-------------------------------------------------------]
00097     protected:
00098         /**
00099         *  @brief
00100         *    Returns the unique system ID of the thread
00101         *
00102         *  @return
00103         *    Thread ID
00104         */
00105         virtual handle GetID() const = 0;
00106 
00107         /**
00108         *  @brief
00109         *    Returns whether the thread is active
00110         *
00111         *  @return
00112         *    'true' if the thread is active
00113         */
00114         virtual bool IsActive() const = 0;
00115 
00116         /**
00117         *  @brief
00118         *    Starts the execution of the thread
00119         *
00120         *  @return
00121         *    'true' if the thread could be started
00122         */
00123         virtual bool Start() = 0;
00124 
00125         /**
00126         *  @brief
00127         *    Stops the execution of the thread
00128         *
00129         *  @return
00130         *    'true' if the thread could be stopped
00131         *
00132         *  @remarks
00133         *    Terminates the thread ungracefully (does not allow proper thread clean up!). Instead of
00134         *    using this function you should signal the thread and wait until it has quit by itself.
00135         *    The internal platform implementation may or may not accept this violent act. For example,
00136         *    Androids Bionic doesn't support it and a call of this method will have no effect at all.
00137         */
00138         virtual bool Terminate() = 0;
00139 
00140         /**
00141         *  @brief
00142         *    Waits until the thread has been stopped
00143         *
00144         *  @return
00145         *    'true' if the thread has been stopped
00146         */
00147         virtual bool Join() = 0;
00148 
00149         /**
00150         *  @brief
00151         *    Waits until the thread has been stopped
00152         *
00153         *  @param[in] nTimeout
00154         *    Time in milliseconds to wait
00155         *
00156         *  @return
00157         *    'true' if the thread has been stopped
00158         */
00159         virtual bool Join(uint64 nTimeout) = 0;
00160 
00161         /**
00162         *  @brief
00163         *    Returns the priority class the thread is in
00164         *
00165         *  @return
00166         *    The priority class the thread is in (type: Thread::EPriorityClass)
00167         */
00168         virtual uint32 GetPriorityClass() const = 0;
00169 
00170         /**
00171         *  @brief
00172         *    Sets the priority class the thread is in
00173         *
00174         *  @param[in] nPriorityClass
00175         *    New priority class the thread is in (type: Thread::EPriorityClass)
00176         *
00177         *  @return
00178         *    'true' if all went fine, else 'false'
00179         */
00180         virtual bool SetPriorityClass(uint32 nPriorityClass) = 0;
00181 
00182         /**
00183         *  @brief
00184         *    Returns the thread priority within the priority class it is in
00185         *
00186         *  @return
00187         *    The thread priority within the priority class it is in (type: Thread::EPriority)
00188         */
00189         virtual uint32 GetPriority() const = 0;
00190 
00191         /**
00192         *  @brief
00193         *    Sets the thread priority within the priority class it is in
00194         *
00195         *  @param[in] nPriority
00196         *    New thread priority within the priority class it is in (type: Thread::EPriority)
00197         *
00198         *  @return
00199         *    'true' if all went fine, else 'false'
00200         */
00201         virtual bool SetPriority(uint32 nPriority) = 0;
00202 
00203 
00204     //[-------------------------------------------------------]
00205     //[ Private data                                          ]
00206     //[-------------------------------------------------------]
00207     private:
00208         Thread *m_pThread;  /**< Pointer to the owning thread (always valid!) */
00209 
00210 
00211 };
00212 
00213 
00214 //[-------------------------------------------------------]
00215 //[ Namespace                                             ]
00216 //[-------------------------------------------------------]
00217 } // PLCore
00218 
00219 
00220 #endif // __PLCORE_THREAD_IMPL_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported