summaryrefslogtreecommitdiff
path: root/src/thread_pthread.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-20 03:44:43 +0000
committerrubidium <rubidium@openttd.org>2009-01-20 03:44:43 +0000
commit82e98c2188b5e449384b6aa07442001aa62bed01 (patch)
tree9998eb5852e48d00ab69b2684a14c266b28117b4 /src/thread_pthread.cpp
parent202aeb83065fa543142a1ae4889fc3d310d9cba4 (diff)
downloadopenttd-82e98c2188b5e449384b6aa07442001aa62bed01.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_pthread.cpp')
-rw-r--r--src/thread_pthread.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/thread_pthread.cpp b/src/thread_pthread.cpp
index 87d524784..2ab3d43f7 100644
--- a/src/thread_pthread.cpp
+++ b/src/thread_pthread.cpp
@@ -83,3 +83,37 @@ private:
if (thread != NULL) *thread = to;
return true;
}
+
+/**
+ * POSIX pthread version of ThreadMutex.
+ */
+class ThreadMutex_pthread : public ThreadMutex {
+private:
+ pthread_mutex_t mutex;
+
+public:
+ ThreadMutex_pthread()
+ {
+ pthread_mutex_init(&this->mutex, NULL);
+ }
+
+ /* virtual */ ~ThreadMutex_pthread()
+ {
+ pthread_mutex_destroy(&this->mutex);
+ }
+
+ /* virtual */ void BeginCritical()
+ {
+ pthread_mutex_lock(&this->mutex);
+ }
+
+ /* virtual */ void EndCritical()
+ {
+ pthread_mutex_unlock(&this->mutex);
+ }
+};
+
+/* static */ ThreadMutex *ThreadMutex::New()
+{
+ return new ThreadMutex_pthread();
+}