Home | History | Annotate | Download | only in decpp
      1 #ifndef _DETHREAD_HPP
      2 #define _DETHREAD_HPP
      3 /*-------------------------------------------------------------------------
      4  * drawElements C++ Base Library
      5  * -----------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief Thread base class.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "deDefs.hpp"
     27 #include "deThread.h"
     28 
     29 namespace de
     30 {
     31 
     32 /*--------------------------------------------------------------------*//*!
     33  * \brief Base class for threads
     34  *
     35  * Thread provides base class for implementing threads. To leverage that
     36  * functionality, inherit Thread in your class and implement virtual run()
     37  * method.
     38  *
     39  * \note Thread class is not thread-safe, i.e. thread control functions
     40  *		 such as start() or join() can not be called from multiple threads
     41  *		 concurrently.
     42  *//*--------------------------------------------------------------------*/
     43 class Thread
     44 {
     45 public:
     46 						Thread			(void);
     47 	virtual				~Thread			(void);
     48 
     49 	void				setPriority		(deThreadPriority priority);
     50 	void				start			(void);
     51 	void				join			(void);
     52 
     53 	bool				isStarted		(void) const;
     54 
     55 	/** Thread entry point. */
     56 	virtual void		run				(void) = DE_NULL;
     57 
     58 private:
     59 						Thread			(const Thread& other); // Not allowed!
     60 	Thread&				operator=		(const Thread& other); // Not allowed!
     61 
     62 	deThreadAttributes	m_attribs;
     63 	deThread			m_thread;
     64 };
     65 
     66 /*--------------------------------------------------------------------*//*!
     67  * \brief Get thread launch status.
     68  * \return true if thread has been started and no join() has been called,
     69  *		   false otherwise.
     70  *//*--------------------------------------------------------------------*/
     71 inline bool Thread::isStarted (void) const
     72 {
     73 	return m_thread != 0;
     74 }
     75 
     76 } // de
     77 
     78 #endif // _DETHREAD_HPP
     79