diff options
author | rubidium <rubidium@openttd.org> | 2009-01-20 03:44:43 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-01-20 03:44:43 +0000 |
commit | 6a3aaef4868ed0812a569c1a048a6511dac80ba7 (patch) | |
tree | 9998eb5852e48d00ab69b2684a14c266b28117b4 /src/thread_win32.cpp | |
parent | bb770717494ec94d54edb4c1dd1f5a7a0c830ead (diff) | |
download | openttd-6a3aaef4868ed0812a569c1a048a6511dac80ba7.tar.xz |
(svn r15159) -Fix: move the UDP queries that resolve a hostname into threads so they don't freeze OpenTTD when for example the network connection got severed. Thanks to glx for writing the mutex implementation for Windows.
Diffstat (limited to 'src/thread_win32.cpp')
-rw-r--r-- | src/thread_win32.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/thread_win32.cpp b/src/thread_win32.cpp index 0cb2825af..882dea9ca 100644 --- a/src/thread_win32.cpp +++ b/src/thread_win32.cpp @@ -93,3 +93,37 @@ private: if (thread != NULL) *thread = to; return true; } + +/** + * Win32 thread version of ThreadMutex. + */ +class ThreadMutex_Win32 : public ThreadMutex { +private: + CRITICAL_SECTION critical_section; + +public: + ThreadMutex_Win32() + { + InitializeCriticalSection(&this->critical_section); + } + + /* virtual */ ~ThreadMutex_Win32() + { + DeleteCriticalSection(&this->critical_section); + } + + /* virtual */ void BeginCritical() + { + EnterCriticalSection(&this->critical_section); + } + + /* virtual */ void EndCritical() + { + LeaveCriticalSection(&this->critical_section); + } +}; + +/* static */ ThreadMutex *ThreadMutex::New() +{ + return new ThreadMutex_Win32(); +} |