Warning, /include/SFML/System/Thread.inl is written in an unsupported language. File is not indexed.
0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 // you must not claim that you wrote the original software.
0015 // If you use this software in a product, an acknowledgment
0016 // in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 // and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024
0025 namespace priv
0026 {
0027 // Base class for abstract thread functions
0028 struct ThreadFunc
0029 {
0030 virtual ~ThreadFunc() {}
0031 virtual void run() = 0;
0032 };
0033
0034 // Specialization using a functor (including free functions) with no argument
0035 template <typename T>
0036 struct ThreadFunctor : ThreadFunc
0037 {
0038 ThreadFunctor(T functor) : m_functor(functor) {}
0039 virtual void run() {m_functor();}
0040 T m_functor;
0041 };
0042
0043 // Specialization using a functor (including free functions) with one argument
0044 template <typename F, typename A>
0045 struct ThreadFunctorWithArg : ThreadFunc
0046 {
0047 ThreadFunctorWithArg(F function, A arg) : m_function(function), m_arg(arg) {}
0048 virtual void run() {m_function(m_arg);}
0049 F m_function;
0050 A m_arg;
0051 };
0052
0053 // Specialization using a member function
0054 template <typename C>
0055 struct ThreadMemberFunc : ThreadFunc
0056 {
0057 ThreadMemberFunc(void(C::*function)(), C* object) : m_function(function), m_object(object) {}
0058 virtual void run() {(m_object->*m_function)();}
0059 void(C::*m_function)();
0060 C* m_object;
0061 };
0062
0063 } // namespace priv
0064
0065
0066 ////////////////////////////////////////////////////////////
0067 template <typename F>
0068 Thread::Thread(F functor) :
0069 m_impl (NULL),
0070 m_entryPoint(new priv::ThreadFunctor<F>(functor))
0071 {
0072 }
0073
0074
0075 ////////////////////////////////////////////////////////////
0076 template <typename F, typename A>
0077 Thread::Thread(F function, A argument) :
0078 m_impl (NULL),
0079 m_entryPoint(new priv::ThreadFunctorWithArg<F, A>(function, argument))
0080 {
0081 }
0082
0083
0084 ////////////////////////////////////////////////////////////
0085 template <typename C>
0086 Thread::Thread(void(C::*function)(), C* object) :
0087 m_impl (NULL),
0088 m_entryPoint(new priv::ThreadMemberFunc<C>(function, object))
0089 {
0090 }