]> git.sesse.net Git - casparcg/blob - SFML-1.6/include/SFML/System/Win32/Thread.hpp
(no commit message)
[casparcg] / SFML-1.6 / include / SFML / System / Win32 / Thread.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\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
8 //\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
12 //\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
17 //\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
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_THREADWIN32_HPP\r
26 #define SFML_THREADWIN32_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/NonCopyable.hpp>\r
32 #include <windows.h>\r
33 \r
34 \r
35 namespace sf\r
36 {\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
42 /// pointer to call\r
43 ////////////////////////////////////////////////////////////\r
44 class SFML_API Thread : NonCopyable\r
45 {\r
46 public :\r
47 \r
48     typedef void (*FuncType)(void*);\r
49 \r
50     ////////////////////////////////////////////////////////////\r
51     /// Construct the thread from a function pointer\r
52     ///\r
53     /// \param Function : Entry point of the thread\r
54     /// \param UserData : Data to pass to the thread function (NULL by default)\r
55     ///\r
56     ////////////////////////////////////////////////////////////\r
57     Thread(FuncType Function, void* UserData = NULL);\r
58 \r
59     ////////////////////////////////////////////////////////////\r
60     /// Virtual destructor\r
61     ///\r
62     ////////////////////////////////////////////////////////////\r
63     virtual ~Thread();\r
64 \r
65     ////////////////////////////////////////////////////////////\r
66     /// Create and run the thread\r
67     ///\r
68     ////////////////////////////////////////////////////////////\r
69     void Launch();\r
70 \r
71     ////////////////////////////////////////////////////////////\r
72     /// Wait until the thread finishes\r
73     ///\r
74     ////////////////////////////////////////////////////////////\r
75     void Wait();\r
76 \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
82     ///\r
83     ////////////////////////////////////////////////////////////\r
84     void Terminate();\r
85 \r
86 protected :\r
87 \r
88     ////////////////////////////////////////////////////////////\r
89     /// Default constructor\r
90     ///\r
91     ////////////////////////////////////////////////////////////\r
92     Thread();\r
93 \r
94 private :\r
95 \r
96     ////////////////////////////////////////////////////////////\r
97     /// Function called as the thread entry point\r
98     ///\r
99     ////////////////////////////////////////////////////////////\r
100     virtual void Run();\r
101 \r
102     ////////////////////////////////////////////////////////////\r
103     /// Actual thread entry point, dispatches to instances\r
104     ///\r
105     /// \param UserData : Data to pass to the thread function\r
106     ///\r
107     /// \return Error code\r
108     ///\r
109     ////////////////////////////////////////////////////////////\r
110     static unsigned int __stdcall ThreadFunc(void* UserData);\r
111 \r
112     ////////////////////////////////////////////////////////////\r
113     // Member data\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
118 };\r
119 \r
120 } // namespace sf\r
121 \r
122 \r
123 #endif // SFML_THREADWIN32_HPP\r