aboutsummaryrefslogtreecommitdiff
path: root/dep/efsw/src/efsw/Thread.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'dep/efsw/src/efsw/Thread.hpp')
-rw-r--r--dep/efsw/src/efsw/Thread.hpp109
1 files changed, 49 insertions, 60 deletions
diff --git a/dep/efsw/src/efsw/Thread.hpp b/dep/efsw/src/efsw/Thread.hpp
index c7da9e8b33c..b60373c2075 100644
--- a/dep/efsw/src/efsw/Thread.hpp
+++ b/dep/efsw/src/efsw/Thread.hpp
@@ -5,107 +5,96 @@
namespace efsw {
-namespace Platform { class ThreadImpl; }
-namespace Private { struct ThreadFunc; }
+namespace Platform {
+class ThreadImpl;
+}
+namespace Private {
+struct ThreadFunc;
+}
/** @brief Thread manager class */
class Thread {
- public:
- typedef void (*FuncType)(void*);
+ public:
+ typedef void ( *FuncType )( void* );
- template <typename F>
- Thread( F function );
+ template <typename F> Thread( F function );
- template <typename F, typename A>
- Thread( F function, A argument );
+ template <typename F, typename A> Thread( F function, A argument );
- template <typename C>
- Thread( void(C::*function)(), C* object );
+ template <typename C> Thread( void ( C::*function )(), C* object );
- virtual ~Thread();
+ virtual ~Thread();
- /** Launch the thread */
- virtual void launch();
+ /** Launch the thread */
+ virtual void launch();
- /** Wait the thread until end */
- void wait();
+ /** Wait the thread until end */
+ void wait();
- /** Terminate the thread */
- void terminate();
- protected:
- Thread();
- private:
- friend class Platform::ThreadImpl;
+ /** Terminate the thread */
+ void terminate();
- /** The virtual function to run in the thread */
- virtual void run();
+ protected:
+ Thread();
- Platform::ThreadImpl * mThreadImpl; ///< OS-specific implementation of the thread
- Private::ThreadFunc * mEntryPoint; ///< Abstraction of the function to run
+ private:
+ friend class Platform::ThreadImpl;
+
+ /** The virtual function to run in the thread */
+ virtual void run();
+
+ Platform::ThreadImpl* mThreadImpl; ///< OS-specific implementation of the thread
+ Private::ThreadFunc* mEntryPoint; ///< Abstraction of the function to run
};
//! NOTE: Taken from SFML2 threads
namespace Private {
// Base class for abstract thread functions
-struct ThreadFunc
-{
+struct ThreadFunc {
virtual ~ThreadFunc() {}
virtual void run() = 0;
};
// Specialization using a functor (including free functions) with no argument
-template <typename T>
-struct ThreadFunctor : ThreadFunc
-{
- ThreadFunctor(T functor) : m_functor(functor) {}
- virtual void run() {m_functor();}
+template <typename T> struct ThreadFunctor : ThreadFunc {
+ ThreadFunctor( T functor ) : m_functor( functor ) {}
+ virtual void run() { m_functor(); }
T m_functor;
};
// Specialization using a functor (including free functions) with one argument
-template <typename F, typename A>
-struct ThreadFunctorWithArg : ThreadFunc
-{
- ThreadFunctorWithArg(F function, A arg) : m_function(function), m_arg(arg) {}
- virtual void run() {m_function(m_arg);}
+template <typename F, typename A> struct ThreadFunctorWithArg : ThreadFunc {
+ ThreadFunctorWithArg( F function, A arg ) : m_function( function ), m_arg( arg ) {}
+ virtual void run() { m_function( m_arg ); }
F m_function;
A m_arg;
};
// Specialization using a member function
-template <typename C>
-struct ThreadMemberFunc : ThreadFunc
-{
- ThreadMemberFunc(void(C::*function)(), C* object) : m_function(function), m_object(object) {}
- virtual void run() {(m_object->*m_function)();}
- void(C::*m_function)();
+template <typename C> struct ThreadMemberFunc : ThreadFunc {
+ ThreadMemberFunc( void ( C::*function )(), C* object ) :
+ m_function( function ), m_object( object ) {}
+ virtual void run() { ( m_object->*m_function )(); }
+ void ( C::*m_function )();
C* m_object;
};
-}
+} // namespace Private
template <typename F>
-Thread::Thread(F functor) :
- mThreadImpl (NULL),
- mEntryPoint( new Private::ThreadFunctor<F>(functor) )
-{
-}
+Thread::Thread( F functor ) :
+ mThreadImpl( NULL ), mEntryPoint( new Private::ThreadFunctor<F>( functor ) ) {}
template <typename F, typename A>
-Thread::Thread(F function, A argument) :
- mThreadImpl(NULL),
- mEntryPoint( new Private::ThreadFunctorWithArg<F efCOMMA A>(function, argument) )
-{
-}
+Thread::Thread( F function, A argument ) :
+ mThreadImpl( NULL ),
+ mEntryPoint( new Private::ThreadFunctorWithArg<F efCOMMA A>( function, argument ) ) {}
template <typename C>
-Thread::Thread(void(C::*function)(), C* object) :
- mThreadImpl(NULL),
- mEntryPoint( new Private::ThreadMemberFunc<C>(function, object) )
-{
-}
+Thread::Thread( void ( C::*function )(), C* object ) :
+ mThreadImpl( NULL ), mEntryPoint( new Private::ThreadMemberFunc<C>( function, object ) ) {}
-}
+} // namespace efsw
#endif