Browse Source

Changed _WIN32 #ifdef to WIN32.
Early-exit Thread::Stop() if already stopped.

Lasse Öörni 14 years ago
parent
commit
9b1a81d84a

+ 2 - 2
Engine/Core/Mutex.cpp

@@ -24,7 +24,7 @@
 #include "Precompiled.h"
 #include "Mutex.h"
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <Windows.h>
 #else
 #include <pthread.h>
@@ -32,7 +32,7 @@
 
 #include "DebugNew.h"
 
-#ifdef _WIN32
+#ifdef WIN32
 Mutex::Mutex() :
     criticalSection_(new CRITICAL_SECTION)
 {

+ 6 - 6
Engine/Core/ProcessUtils.cpp

@@ -29,7 +29,7 @@
 #include <cstdlib>
 #include <fcntl.h>
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <Windows.h>
 #include <io.h>
 #else
@@ -38,7 +38,7 @@
 
 #include "DebugNew.h"
 
-#ifdef _WIN32
+#ifdef WIN32
 static bool consoleOpened = false;
 #endif
 static String currentLine;
@@ -47,7 +47,7 @@ static Mutex staticMutex;
 
 void ErrorDialog(const char* title, const char* message)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     MessageBox(0, message, title, 0);
     #else
     printf("%s\n", message);
@@ -62,7 +62,7 @@ void ErrorExit(const String& message, int exitCode)
 
 void OpenConsoleWindow()
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     if (consoleOpened)
         return;
     
@@ -151,7 +151,7 @@ String GetConsoleInput()
 {
     String ret;
     
-    #ifdef _WIN32
+    #ifdef WIN32
     HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
     if (input == INVALID_HANDLE_VALUE)
         return ret;
@@ -215,7 +215,7 @@ String GetConsoleInput()
 
 unsigned GetNumCPUCores()
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     SYSTEM_INFO info;
     GetSystemInfo(&info);
     return info.dwNumberOfProcessors;

+ 9 - 5
Engine/Core/Thread.cpp

@@ -24,7 +24,7 @@
 #include "Precompiled.h"
 #include "Thread.h"
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <Windows.h>
 #else
 #include <pthread.h>
@@ -32,7 +32,7 @@
 
 #include "DebugNew.h"
 
-#ifdef _WIN32
+#ifdef WIN32
 DWORD WINAPI ThreadFunctionStatic(void* data)
 {
     Thread* thread = static_cast<Thread*>(data);
@@ -67,7 +67,7 @@ bool Thread::Start()
         return false;
     
     shouldRun_ = true;
-    #ifdef _WIN32
+    #ifdef WIN32
     handle_ = CreateThread(0, 0, ThreadFunctionStatic, this, 0, 0);
     #else
     handle_ = new pthread_t;
@@ -81,8 +81,12 @@ bool Thread::Start()
 
 void Thread::Stop()
 {
+    // Check if already stopped
+    if (!handle_)
+        return;
+    
     shouldRun_ = false;
-    #ifdef _WIN32
+    #ifdef WIN32
     WaitForSingleObject((HANDLE)handle_, INFINITE);
     CloseHandle((HANDLE)handle_);
     #else
@@ -96,7 +100,7 @@ void Thread::Stop()
 
 void Thread::SetPriority(int priority)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     if (handle_)
         SetThreadPriority((HANDLE)handle_, priority);
     #endif

+ 8 - 8
Engine/Core/Timer.cpp

@@ -25,7 +25,7 @@
 #include "CoreEvents.h"
 #include "Timer.h"
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <Windows.h>
 #include <MMSystem.h>
 #else
@@ -48,7 +48,7 @@ Time::Time(Context* context) :
     totalMSec_(0),
     timerPeriod_(0)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     LARGE_INTEGER frequency;
     if (QueryPerformanceFrequency(&frequency))
     {
@@ -114,7 +114,7 @@ void Time::EndFrame()
 
 void Time::SetTimerPeriod(unsigned mSec)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     if (timerPeriod_ > 0)
         timeEndPeriod(timerPeriod_);
     
@@ -127,7 +127,7 @@ void Time::SetTimerPeriod(unsigned mSec)
 
 void Time::Sleep(unsigned mSec)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     ::Sleep(mSec);
     #else
     usleep(mSec * 1000);
@@ -141,7 +141,7 @@ Timer::Timer()
 
 unsigned Timer::GetMSec(bool reset)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     unsigned currentTime = timeGetTime();
     #else
     struct timeval time;
@@ -158,7 +158,7 @@ unsigned Timer::GetMSec(bool reset)
 
 void Timer::Reset()
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     startTime_ = timeGetTime();
     #else
     struct timeval time;
@@ -176,7 +176,7 @@ long long HiresTimer::GetUSec(bool reset)
 {
     long long currentTime;
     
-    #ifdef _WIN32
+    #ifdef WIN32
     if (supported)
     {
         LARGE_INTEGER counter;
@@ -205,7 +205,7 @@ long long HiresTimer::GetUSec(bool reset)
 
 void HiresTimer::Reset()
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     if (supported)
     {
         LARGE_INTEGER counter;

+ 13 - 13
Engine/IO/FileSystem.cpp

@@ -31,14 +31,14 @@
 #include <cstdio>
 #include <cstring>
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <Windows.h>
 #include <Shellapi.h>
 #include <direct.h>
 #include <process.h>
 // Enable SHGetSpecialFolderPath on MinGW
 #ifndef _MSC_VER
-#define _WIN32_IE 0x0400
+#define WIN32_IE 0x0400
 #endif
 #include <Shlobj.h>
 #else
@@ -75,7 +75,7 @@ bool FileSystem::SetCurrentDir(const String& pathName)
         LOGERROR("Access denied to " + pathName);
         return false;
     }
-    #ifdef _WIN32
+    #ifdef WIN32
     if (SetCurrentDirectory(GetNativePath(pathName).CString()) == FALSE)
     {
         LOGERROR("Failed to change directory to " + pathName);
@@ -99,7 +99,7 @@ bool FileSystem::CreateDir(const String& pathName)
         return false;
     }
     
-    #ifdef _WIN32
+    #ifdef WIN32
     bool success = (CreateDirectory(GetNativePath(RemoveTrailingSlash(pathName)).CString(), 0) == TRUE) ||
         (GetLastError() == ERROR_ALREADY_EXISTS);
     #else
@@ -131,7 +131,7 @@ int FileSystem::SystemRun(const String& fileName, const Vector<String>& argument
     {
         String fixedFileName = GetNativePath(fileName);
         
-        #ifdef _WIN32
+        #ifdef WIN32
         PODVector<const char*> argPtrs;
         argPtrs.Push(fixedFileName.CString());
         for (unsigned i = 0; i < arguments.Size(); ++i)
@@ -174,7 +174,7 @@ int FileSystem::SystemRun(const String& fileName, const Vector<String>& argument
 
 bool FileSystem::SystemOpen(const String& fileName, const String& mode)
 {
-    #ifdef _WIN32
+    #ifdef WIN32
     if (allowedPaths_.Empty())
     {
         if (!FileExists(fileName) && !DirExists(fileName))
@@ -261,7 +261,7 @@ String FileSystem::GetCurrentDir()
     char path[MAX_PATH];
     path[0] = 0;
     
-    #ifdef _WIN32
+    #ifdef WIN32
     GetCurrentDirectory(MAX_PATH, path);
     #else
     getcwd(path, MAX_PATH);
@@ -300,7 +300,7 @@ bool FileSystem::FileExists(const String& fileName)
         return false;
     
     String fixedName = GetNativePath(RemoveTrailingSlash(fileName));
-    #ifdef _WIN32
+    #ifdef WIN32
     DWORD attributes = GetFileAttributes(fixedName.CString());
     if (attributes == INVALID_FILE_ATTRIBUTES || attributes & FILE_ATTRIBUTE_DIRECTORY)
         return false;
@@ -319,7 +319,7 @@ bool FileSystem::DirExists(const String& pathName)
         return false;
     
     String fixedName = GetNativePath(RemoveTrailingSlash(pathName));
-    #ifdef _WIN32
+    #ifdef WIN32
     DWORD attributes = GetFileAttributes(fixedName.CString());
     if (attributes == INVALID_FILE_ATTRIBUTES || !(attributes & FILE_ATTRIBUTE_DIRECTORY))
         return false;
@@ -348,7 +348,7 @@ String FileSystem::GetProgramDir()
     char exeName[MAX_PATH];
     memset(exeName, 0, MAX_PATH);
     
-    #ifdef _WIN32
+    #ifdef WIN32
     GetModuleFileName(0, exeName, MAX_PATH);
     #endif
     #ifdef __APPLE__
@@ -368,7 +368,7 @@ String FileSystem::GetUserDocumentsDir()
 {
     char pathName[MAX_PATH];
     pathName[0] = 0;
-    #ifdef _WIN32
+    #ifdef WIN32
     SHGetSpecialFolderPath(0, pathName, CSIDL_PERSONAL, 0);
     #else
     strcpy(pathName, getenv("HOME"));
@@ -393,7 +393,7 @@ void FileSystem::ScanDirInternal(Vector<String>& result, String path, const Stri
     if (path.Length() > startPath.Length())
         deltaPath = path.Substring(startPath.Length());
     
-    #ifdef _WIN32
+    #ifdef WIN32
     WIN32_FIND_DATA info;
     HANDLE handle = FindFirstFile(pathAndFilter.CString(), &info);
     if (handle != INVALID_HANDLE_VALUE)
@@ -542,7 +542,7 @@ String GetInternalPath(const String& pathName)
 
 String GetNativePath(const String& pathName)
 {
-#ifdef _WIN32
+#ifdef WIN32
     String ret = pathName;
     ret.Replace('/', '\\');
     return ret;

+ 2 - 2
Urho3D/Urho3D.cpp

@@ -32,7 +32,7 @@
 
 #include <stdexcept>
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <Windows.h>
 #endif
 
@@ -40,7 +40,7 @@
 
 void Run(const char* cmdLine);
 
-#ifdef _WIN32
+#ifdef WIN32
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
 {
     #if defined(_MSC_VER) && defined(_DEBUG)