Index: src/xplcommon/Makefile.am
===================================================================
--- src/xplcommon/Makefile.am	(revision 31)
+++ src/xplcommon/Makefile.am	(revision 32)
@@ -27,6 +27,7 @@
 	types.h			\
 	PseudoRandom.h		\
+	Thread.h		\
+	Mutex.h			\
 	Failable.h		\
-	Thread.h		\
 	Waiter.h		\
 	WaitableEvent.h		\
Index: src/xplcommon/Mutex.h
===================================================================
--- src/xplcommon/Mutex.h	(revision 32)
+++ src/xplcommon/Mutex.h	(revision 32)
@@ -0,0 +1,110 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_MUTEX_H
+#define XPLCOMMON_MUTEX_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of a mutex
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A mutual exclusion device.
+ */
+class Mutex
+{
+public:
+    /**
+     * Lock the mutex. If the mutex is locked by another thread, the
+     * caller one waits until the other thread releases the mutex.
+     */
+    void lock();
+
+    /**
+     * Try to lock the mutex. If the mutex is locked by another
+     * thread, this function returns false immediately. Otherwise it
+     * locks the mutex and returns true.
+     */
+    bool tryLock();
+
+    /**
+     * Unlock the mutex.
+     */
+    void unlock();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of a mutex
+
+//------------------------------------------------------------------------------
+
+#include "config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+
+#include "win32/Mutex.h"
+
+namespace xplcommon { typedef win32::Mutex Mutex; }
+
+//------------------------------------------------------------------------------
+
+#else // TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+
+#include "posix/Mutex.h"
+
+namespace xplcommon { typedef posix::Mutex Mutex; }
+
+//------------------------------------------------------------------------------
+
+#endif // TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_MUTEX_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Makefile.am
===================================================================
--- src/xplcommon/posix/Makefile.am	(revision 21)
+++ src/xplcommon/posix/Makefile.am	(revision 32)
@@ -21,4 +21,5 @@
 include_xplcommon_posix_HEADERS=\
 	Thread.h		\
+	Mutex.h			\
 	Waitable.h		\
 	Waiter.h		\
Index: src/xplcommon/posix/Mutex.h
===================================================================
--- src/xplcommon/posix/Mutex.h	(revision 32)
+++ src/xplcommon/posix/Mutex.h	(revision 32)
@@ -0,0 +1,131 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_POSIX_MUTEX_H
+#define XPLCOMMON_POSIX_MUTEX_H
+//------------------------------------------------------------------------------
+
+#include <pthread.h>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace posix {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Mutual exclusion device for POSIX threads.
+ */
+class Mutex
+{
+private:
+    /**
+     * The mutex structure.
+     */
+    pthread_mutex_t mutex;
+
+public:
+    /**
+     * Construct the mutex.
+     */
+    Mutex();
+
+    /**
+     * Destroy the mutex.
+     */
+    ~Mutex();
+
+    /**
+     * Lock the mutex. If the mutex is locked by another thread, the
+     * caller one waits until the other thread releases the mutex.
+     */
+    void lock();
+
+    /**
+     * Try to lock the mutex. If the mutex is locked by another
+     * thread, this function returns false immediately. Otherwise it
+     * locks the mutex and returns true.
+     */
+    bool tryLock();
+
+    /**
+     * Unlock the mutex.
+     */
+    void unlock();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Mutex::Mutex()
+{
+    pthread_mutex_init(&mutex, 0);
+}
+
+//------------------------------------------------------------------------------
+
+inline Mutex::~Mutex()
+{
+    pthread_mutex_destroy(&mutex);
+}
+
+//------------------------------------------------------------------------------
+
+inline void Mutex::lock()
+{
+    pthread_mutex_lock(&mutex);
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Mutex::tryLock()
+{
+    return pthread_mutex_trylock(&mutex)==0;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Mutex::unlock()
+{
+    pthread_mutex_unlock(&mutex);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::posix */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_POSIX_MUTEX_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Makefile.am
===================================================================
--- src/xplcommon/win32/Makefile.am	(revision 26)
+++ src/xplcommon/win32/Makefile.am	(revision 32)
@@ -16,4 +16,5 @@
 include_xplcommon_win32_HEADERS=\
 	Thread.h		\
+	Mutex.h			\
 	EventFailable.h		\
 	Event.h			\
Index: src/xplcommon/win32/Mutex.h
===================================================================
--- src/xplcommon/win32/Mutex.h	(revision 32)
+++ src/xplcommon/win32/Mutex.h	(revision 32)
@@ -0,0 +1,131 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WIN32_MUTEX_H
+#define XPLCOMMON_WIN32_MUTEX_H
+//------------------------------------------------------------------------------
+
+#include <windows.h>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace win32 {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Mutual exclusion device implementation for Windows.
+ */
+class Mutex
+{
+private:
+    /**
+     * The handle of the mutex.
+     */
+    HANDLE mutex;
+
+public:
+    /**
+     * Construct the mutex.
+     */
+    Mutex();
+
+    /**
+     * Destroy the mutex.
+     */
+    ~Mutex();
+
+    /**
+     * Lock the mutex. If the mutex is locked by another thread, the
+     * caller one waits until the other thread releases the mutex.
+     */
+    void lock();
+
+    /**
+     * Try to lock the mutex. If the mutex is locked by another
+     * thread, this function returns false immediately. Otherwise it
+     * locks the mutex and returns true.
+     */
+    bool tryLock();
+
+    /**
+     * Unlock the mutex.
+     */
+    void unlock();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Mutex::Mutex() :
+    mutex(CreateMutex(0, false, 0))
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline Mutex::~Mutex()
+{
+    CloseHandle(mutex);
+}
+
+//------------------------------------------------------------------------------
+
+inline void Mutex::lock()
+{
+    WaitForSingleObject(mutex, INFINITE);
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Mutex::tryLock()
+{
+    return WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Mutex::unlock()
+{
+    ReleaseMutex(mutex);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::win32 */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WIN32_MUTEX_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
