1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_THREADWIN32_HPP
\r
26 #define SFML_THREADWIN32_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/System/NonCopyable.hpp>
\r
32 #include <windows.h>
\r
37 ////////////////////////////////////////////////////////////
\r
38 /// Thread defines an easy way to manipulate a thread.
\r
39 /// There are two ways to use Thread :
\r
40 /// - Inherit from it and override the Run() virtual function
\r
41 /// - Construct a Thread instance and pass it a function
\r
43 ////////////////////////////////////////////////////////////
\r
44 class SFML_API Thread : NonCopyable
\r
48 typedef void (*FuncType)(void*);
\r
50 ////////////////////////////////////////////////////////////
\r
51 /// Construct the thread from a function pointer
\r
53 /// \param Function : Entry point of the thread
\r
54 /// \param UserData : Data to pass to the thread function (NULL by default)
\r
56 ////////////////////////////////////////////////////////////
\r
57 Thread(FuncType Function, void* UserData = NULL);
\r
59 ////////////////////////////////////////////////////////////
\r
60 /// Virtual destructor
\r
62 ////////////////////////////////////////////////////////////
\r
65 ////////////////////////////////////////////////////////////
\r
66 /// Create and run the thread
\r
68 ////////////////////////////////////////////////////////////
\r
71 ////////////////////////////////////////////////////////////
\r
72 /// Wait until the thread finishes
\r
74 ////////////////////////////////////////////////////////////
\r
77 ////////////////////////////////////////////////////////////
\r
78 /// Terminate the thread
\r
79 /// Terminating a thread with this function is not safe,
\r
80 /// you should rather try to make the thread function
\r
81 /// terminate by itself
\r
83 ////////////////////////////////////////////////////////////
\r
88 ////////////////////////////////////////////////////////////
\r
89 /// Default constructor
\r
91 ////////////////////////////////////////////////////////////
\r
96 ////////////////////////////////////////////////////////////
\r
97 /// Function called as the thread entry point
\r
99 ////////////////////////////////////////////////////////////
\r
100 virtual void Run();
\r
102 ////////////////////////////////////////////////////////////
\r
103 /// Actual thread entry point, dispatches to instances
\r
105 /// \param UserData : Data to pass to the thread function
\r
107 /// \return Error code
\r
109 ////////////////////////////////////////////////////////////
\r
110 static unsigned int __stdcall ThreadFunc(void* UserData);
\r
112 ////////////////////////////////////////////////////////////
\r
114 ////////////////////////////////////////////////////////////
\r
115 HANDLE myHandle; ///< Win32 thread handle
\r
116 FuncType myFunction; ///< Function to call as the thread entry point
\r
117 void* myUserData; ///< Data to pass to the thread function
\r
123 #endif // SFML_THREADWIN32_HPP
\r