00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00026 // Headers 00028 #include <SFML/System/Win32/ThreadImpl.hpp> 00029 #include <SFML/System/Thread.hpp> 00030 #include <SFML/System/Err.hpp> 00031 #include <process.h> 00032 00033 00034 namespace sf 00035 { 00036 namespace priv 00037 { 00039 ThreadImpl::ThreadImpl(Thread* owner) 00040 { 00041 myThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, NULL)); 00042 00043 if (!myThread) 00044 Err() << "Failed to create thread" << std::endl; 00045 } 00046 00047 00049 ThreadImpl::~ThreadImpl() 00050 { 00051 if (myThread) 00052 CloseHandle(myThread); 00053 } 00054 00055 00057 void ThreadImpl::Wait() 00058 { 00059 if (myThread) 00060 WaitForSingleObject(myThread, INFINITE); 00061 } 00062 00063 00065 void ThreadImpl::Terminate() 00066 { 00067 if (myThread) 00068 TerminateThread(myThread, 0); 00069 } 00070 00071 00073 unsigned int __stdcall ThreadImpl::EntryPoint(void* userData) 00074 { 00075 // The Thread instance is stored in the user data 00076 Thread* owner = static_cast<Thread*>(userData); 00077 00078 // Forward to the owner 00079 owner->Run(); 00080 00081 // Optional, but it is cleaner 00082 _endthreadex(0); 00083 00084 return 0; 00085 } 00086 00087 } // namespace priv 00088 00089 } // namespace sf
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::