Index: src/xplcommon/Makefile.am
===================================================================
--- src/xplcommon/Makefile.am	(revision 2)
+++ src/xplcommon/Makefile.am	(revision 3)
@@ -1,2 +1,10 @@
+SUBDIRS=
+if TARGET_API_POSIX
+SUBDIRS+=posix
+endif
+if TARGET_API_WIN32
+SUBDIRS+=win32
+endif
+
 lib_LTLIBRARIES=libxplcommon.la
 
@@ -4,20 +12,13 @@
 
 if TARGET_API_POSIX
-libxplcommon_la_SOURCES +=	\
-	POSIXThread.cc		\
-	POSIXWaitable.cc	\
-	POSIXWaiter.cc
+libxplcommon_la_LIBADD=posix/libxplcommon_posix.la
 endif
 
 if TARGET_API_WIN32
-libxplcommon_la_SOURCES +=	\
-	Win32Thread.cc
+libxplcommon_la_LIBADD=win32/libxplcommon_win32.la
 endif
 
 include_xplcommondir=$(includedir)/xplcommon
 include_xplcommon_HEADERS=\
-	POSIXThread.h		\
-	Win32Thread.h		\
-	Thread.h		\
-	POSIXWaitable.h		\
-	POSIXWaiter.h
+	config.h	\
+	Thread.h
Index: src/xplcommon/POSIXThread.cc
===================================================================
--- src/xplcommon/POSIXThread.cc	(revision 1)
+++ 	(revision )
@@ -1,59 +1,0 @@
-// 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.
-
-//------------------------------------------------------------------------------
-
-#include "config.h"
-#ifdef HAVE_PTHREAD_H
-
-//------------------------------------------------------------------------------
-
-#include "POSIXThread.h"
-
-//------------------------------------------------------------------------------
-
-using xplcommon::POSIXThread;
-
-//------------------------------------------------------------------------------
-
-void* POSIXThread::threadFn(void* arg)
-{
-    reinterpret_cast<POSIXThread*>(arg)->run();
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-#endif // HAVE_PTHREAD_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/POSIXThread.h
===================================================================
--- src/xplcommon/POSIXThread.h	(revision 1)
+++ 	(revision )
@@ -1,128 +1,0 @@
-// 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_POSIXTHREAD_H
-#define XPLCOMMON_POSIXTHREAD_H
-//------------------------------------------------------------------------------
-
-#include "config.h"
-
-#ifdef HAVE_PTHREAD_H
-
-//------------------------------------------------------------------------------
-
-#include <pthread.h>
-
-//------------------------------------------------------------------------------
-
-namespace xplcommon {
-
-//------------------------------------------------------------------------------
-
-/**
- * A pthreads-based thread implementation.
- */
-class POSIXThread
-{
-private:
-    /**
-     * The thread-runner function.
-     */
-    static void* threadFn(void* arg);
-
-    /**
-     * The posix thread handle.
-     */
-    pthread_t thread;
-
-public:
-    /**
-     * Virtual destructor.
-     */
-    virtual ~POSIXThread();
-
-    /**
-     * Start the thread.
-     *
-     * @return if the thread could be started
-     */
-    bool start();
-
-    /**
-     * Perform the thread's real operation.
-     */
-    virtual void run() = 0;
-
-    /**
-     * Wait for the thread to quit.
-     */
-    void join();
-};
-
-//------------------------------------------------------------------------------
-
-/// Common type for OS-independent code
-typedef POSIXThread Thread;
-
-//------------------------------------------------------------------------------
-// Inline definitions
-//------------------------------------------------------------------------------
-
-inline POSIXThread::~POSIXThread()
-{
-}
-
-//------------------------------------------------------------------------------
-
-inline bool POSIXThread::start()
-{
-    return pthread_create(&thread, 0, &threadFn, this)>=0;
-}
-
-//------------------------------------------------------------------------------
-
-inline void POSIXThread::join()
-{
-    pthread_join(thread, 0);
-}
-
-//------------------------------------------------------------------------------
-
-} /* namespace xplcommon */
-
-//------------------------------------------------------------------------------
-#endif // HAVE_PTHREAD_H
-
-#endif // XPLCOMMON_POSIXTHREAD_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/POSIXWaitable.cc
===================================================================
--- src/xplcommon/POSIXWaitable.cc	(revision 1)
+++ 	(revision )
@@ -1,69 +1,0 @@
-// 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.
-
-//------------------------------------------------------------------------------
-
-#include "config.h"
-#ifdef HAVE_POLL_H
-
-//------------------------------------------------------------------------------
-
-#include "POSIXWaitable.h"
-
-#include "POSIXWaiter.h"
-
-//------------------------------------------------------------------------------
-
-using xplcommon::POSIXWaitable;
-
-//------------------------------------------------------------------------------
-
-POSIXWaitable::POSIXWaitable(POSIXWaiter* waiter, int fd, short events) :
-    waiter(waiter),
-    fd(fd),
-    events(events)
-{
-    if (waiter!=0) waiter->add(this);
-}
-
-//------------------------------------------------------------------------------
-
-POSIXWaitable::~POSIXWaitable()
-{
-    if (waiter!=0) waiter->remove(this);
-}
-
-//------------------------------------------------------------------------------
-#endif // HAVE_POLL_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/POSIXWaitable.h
===================================================================
--- src/xplcommon/POSIXWaitable.h	(revision 1)
+++ 	(revision )
@@ -1,118 +1,0 @@
-// 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_POSIXWAITABLE_H
-#define XPLCOMMON_POSIXWAITABLE_H
-//------------------------------------------------------------------------------
-
-#include "config.h"
-
-#ifdef HAVE_POLL_H
-
-//------------------------------------------------------------------------------
-
-namespace xplcommon {
-
-//------------------------------------------------------------------------------
-
-class POSIXWaiter;
-
-//------------------------------------------------------------------------------
-
-/**
- * Base class of objects for which one can wait in a POSIXWaiter.
- *
- * It is basically a file descriptor.
- */
-class POSIXWaitable
-{
-protected:
-    /**
-     * The waiter this waitable belongs to, if any.
-     */
-    POSIXWaiter* waiter;
-
-    /**
-     * The file descriptor
-     */
-    int fd;
-
-    /**
-     * The events this waitable is interested in.
-     */
-    short events;
-
-protected:
-    /**
-     * Construct the waitable.
-     */
-    POSIXWaitable(POSIXWaiter* waiter, int fd = -1, short events = 0);
-
-public:
-    /**
-     * Destroy the waitable. It will be removed from the waiter.
-     */
-    virtual ~POSIXWaitable();
-
-    /**
-     * Indicate if the waitable is ready, i.e. there is no need to
-     * wait for it.
-     *
-     * Calling this function should not deleted the ready
-     * indication. It should be deleted by actually processing the data.
-     */
-    virtual bool ready() = 0;
-
-protected:
-    /**
-     * Handle the given events.
-     */
-    virtual void handleEvents(short events) = 0;
-
-    friend class POSIXWaiter;
-};
-
-//------------------------------------------------------------------------------
-
-typedef POSIXWaitable Waitable;
-
-//------------------------------------------------------------------------------
-
-} /* namespace xplcommon */
-
-//------------------------------------------------------------------------------
-#endif // HAVE_POLL_H
-
-#endif // XPLCOMMON_POSIXWAITABLE_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/POSIXWaiter.cc
===================================================================
--- src/xplcommon/POSIXWaiter.cc	(revision 1)
+++ 	(revision )
@@ -1,158 +1,0 @@
-// 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.
-
-//------------------------------------------------------------------------------
-
-#include "config.h"
-#ifdef HAVE_POLL_H
-
-//------------------------------------------------------------------------------
-
-#include "POSIXWaiter.h"
-#include "POSIXWaitable.h"
-
-#include <cassert>
-#include <cstdio>
-
-//------------------------------------------------------------------------------
-
-using xplcommon::POSIXWaiter;
-
-//------------------------------------------------------------------------------
-
-inline bool POSIXWaiter::hasReady() const
-{
-    for(waitables_t::const_iterator i = waitables.begin(); i!=waitables.end();
-        ++i)
-    {
-        POSIXWaitable* waitable = i->second;
-        if (waitable->ready()) return true;
-    }
-    return false;
-}
-
-//------------------------------------------------------------------------------
-
-inline size_t POSIXWaiter::setupPollFDs(pollfd* pollFDs)
-{
-    size_t numValid = 0;
-
-    for(waitables_t::const_iterator i = waitables.begin(); i!=waitables.end();
-        ++i)
-    {
-        POSIXWaitable* waitable = i->second;
-        if (waitable->events==0) continue;
-
-        pollfd& pollFD = pollFDs[numValid++];
-
-        pollFD.fd = waitable->fd;
-        pollFD.events = waitable->events;
-        pollFD.revents = 0;
-    }
-
-    return numValid;
-}
-
-//------------------------------------------------------------------------------
-
-inline void POSIXWaiter::processPollFDs(const pollfd* pollFDs, size_t size)
-{
-    for(size_t i = 0; i<size; ++i) {
-        const pollfd& pollFD = pollFDs[i];
-        if (pollFD.revents!=0) {
-            waitables_t::iterator j = waitables.find(pollFD.fd);
-            assert(j!=waitables.end());
-            POSIXWaitable* waitable = j->second;
-            waitable->handleEvents(pollFD.revents);
-        }
-    }
-}
-
-//------------------------------------------------------------------------------
-
-POSIXWaiter::~POSIXWaiter()
-{
-    for(waitables_t::iterator i = waitables.begin(); i!=waitables.end(); ++i)
-    {
-        POSIXWaitable* waitable = i->second;
-        waitable->waiter = 0;
-    }
-}
-
-//------------------------------------------------------------------------------
-
-bool POSIXWaiter::wait(int timeout)
-{
-    if (hasReady()) return true;
-
-    pollfd pollFDs[numWaitables];
-    size_t numValid = setupPollFDs(pollFDs);
-
-    int result = poll(pollFDs, numValid, timeout);
-
-    if (result<0) {
-        perror("POSIXWaiter::wait: poll");
-        return false;
-    } else if (result>0) {
-        processPollFDs(pollFDs, numValid);
-    }
-
-    return hasReady();
-}
-
-//------------------------------------------------------------------------------
-
-void POSIXWaiter::add(POSIXWaitable* waitable)
-{
-    assert(waitable->fd>=0);
-    assert(waitables.find(waitable->fd)==waitables.end());
-    waitables[waitable->fd] = waitable;
-    ++numWaitables;
-}
-
-//------------------------------------------------------------------------------
-
-void POSIXWaiter::remove(POSIXWaitable* waitable)
-{
-    assert(numWaitables>0);
-    assert(waitables.find(waitable->fd)!=waitables.end());
-    assert(waitables[waitable->fd]==waitable);
-    waitables.erase(waitable->fd);
-    --numWaitables;
-}
-
-
-//------------------------------------------------------------------------------
-#endif // HAVE_POLL_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/POSIXWaiter.h
===================================================================
--- src/xplcommon/POSIXWaiter.h	(revision 1)
+++ 	(revision )
@@ -1,165 +1,0 @@
-// 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_POSIXWAITER_H
-#define XPLCOMMON_POSIXWAITER_H
-//------------------------------------------------------------------------------
-
-#include "config.h"
-
-#ifdef HAVE_POLL_H
-
-//------------------------------------------------------------------------------
-
-#include <map>
-
-#include <cstdlib>
-
-#include <poll.h>
-
-//------------------------------------------------------------------------------
-
-namespace xplcommon {
-
-//------------------------------------------------------------------------------
-
-class POSIXWaitable;
-
-//------------------------------------------------------------------------------
-
-/**
- * Class that can be used to register waitable objects and then wait
- * for them.
- */
-class POSIXWaiter
-{
-private:
-    /**
-     * Type for the set of waitables.
-     */
-    typedef std::map<int, POSIXWaitable*> waitables_t;
-
-    /**
-     * The set of waitables belonging to this waiter.
-     */
-    waitables_t waitables;
-
-    /**
-     * The number of waitables.
-     */
-    size_t numWaitables;
-
-public:
-    /**
-     * Construct the waiter.
-     */
-    POSIXWaiter();
-
-    /**
-     * Destroy the waiter. All waitables that still exists will be
-     * modified to point to no waiter.
-     */
-    ~POSIXWaiter();
-
-    /**
-     * Wait for any if the waitables to become ready or until a
-     * timeout expires.
-     *
-     * If any of the waitables are ready, the function returns immediately.
-     *
-     * @return true if any of the waitables has become ready, false if
-     * the timeout occurs.
-     */
-    bool wait(int timeout = -1);
-
-protected:
-    /**
-     * Add a waitable.
-     */
-    void add(POSIXWaitable* waitable);
-
-    /**
-     * Remove a waitable.
-     */
-    void remove(POSIXWaitable* waitable);
-
-private:
-    /**
-     * Determine if any of the waitables is ready.
-     */
-    bool hasReady() const;
-
-    /**
-     * Fill the given array of poll descriptors with those file
-     * descriptors that wait for an event.
-     *
-     * @param pollFDs the file descriptor array to fill. It should
-     * contain at least as many elements as the number of waitables.
-     *
-     * @return the number of valid poll file descriptors.
-     */
-    size_t setupPollFDs(pollfd* pollFDs);
-
-    /**
-     * Process the given array of poll descriptors. For each
-     * descriptor, if its events are not 0, the handleEvents()
-     * function of the corresponding waitable is called.
-     */
-    void processPollFDs(const pollfd* pollFDs, size_t size);
-
-    friend class POSIXWaitable;
-};
-
-//------------------------------------------------------------------------------
-
-typedef POSIXWaiter Waiter;
-
-//------------------------------------------------------------------------------
-// Inline definitions
-//------------------------------------------------------------------------------
-
-inline POSIXWaiter::POSIXWaiter() :
-    numWaitables(0)
-{
-}
-
-//------------------------------------------------------------------------------
-
-} /* namespace xplcommon */
-
-//------------------------------------------------------------------------------
-#endif // HAVE_POLL_H
-
-#endif // XPLCOMMON_POSIXWAITABLE_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/Thread.h
===================================================================
--- src/xplcommon/Thread.h	(revision 1)
+++ src/xplcommon/Thread.h	(revision 3)
@@ -34,13 +34,23 @@
 #include "config.h"
 
-#ifdef HAVE_WINDOWS_H
+//------------------------------------------------------------------------------
 
-#include "Win32Thread.h"
+#if TARGET_API_WIN32
 
-#else
+#include "win32/Thread.h"
 
-#include "POSIXThread.h"
+namespace xplcommon { typedef win32::Thread Thread; }
 
-#endif
+//------------------------------------------------------------------------------
+#else // TARGET_API_WIN32
+//------------------------------------------------------------------------------
+
+#include "posix/Thread.h"
+
+namespace xplcommon { typedef posix::Thread Thread; }
+
+//------------------------------------------------------------------------------
+
+#endif // TARGET_API_WIN32
 
 //------------------------------------------------------------------------------
Index: src/xplcommon/Win32Thread.cc
===================================================================
--- src/xplcommon/Win32Thread.cc	(revision 1)
+++ 	(revision )
@@ -1,59 +1,0 @@
-// 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.
-
-//------------------------------------------------------------------------------
-
-#include "config.h"
-#ifdef HAVE_WINDOWS_H
-
-//------------------------------------------------------------------------------
-
-#include "Win32Thread.h"
-
-//------------------------------------------------------------------------------
-
-using xplcommon::Win32Thread;
-
-//------------------------------------------------------------------------------
-
-DWORD Win32Thread::threadFn(LPVOID arg)
-{
-    reinterpret_cast<Win32Thread*>(arg)->run();
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-#endif // HAVE_PTHREAD_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/Win32Thread.h
===================================================================
--- src/xplcommon/Win32Thread.h	(revision 1)
+++ 	(revision )
@@ -1,128 +1,0 @@
-// 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_WIN32THREAD_H
-#define XPLCOMMON_WIN32THREAD_H
-//------------------------------------------------------------------------------
-
-#include "config.h"
-
-#ifdef HAVE_WINDOWS_H
-//------------------------------------------------------------------------------
-
-#include <windows.h>
-
-//------------------------------------------------------------------------------
-
-namespace xplcommon {
-
-//------------------------------------------------------------------------------
-
-/**
- * A Win32 API thread implementation.
- */
-class Win32Thread
-{
-private:
-    /**
-     * The thread-runner function.
-     */
-    static DWORD WINAPI threadFn(LPVOID arg);
-
-    /**
-     * The thread handle.
-     */
-    HANDLE handle;
-
-public:
-    /**
-     * Virtual destructor.
-     */
-    virtual ~Win32Thread();
-
-    /**
-     * Start the thread.
-     *
-     * @return if the thread could be started
-     */
-    bool start();
-
-    /**
-     * Perform the thread's real operation.
-     */
-    virtual void run() = 0;
-
-    /**
-     * Wait for the thread to quit.
-     */
-    void join();
-};
-
-//------------------------------------------------------------------------------
-
-/// Common type for OS-independent code
-typedef Win32Thread Thread;
-
-//------------------------------------------------------------------------------
-// Inline definitions
-//------------------------------------------------------------------------------
-
-inline Win32Thread::~Win32Thread()
-{
-}
-
-//------------------------------------------------------------------------------
-
-inline bool Win32Thread::start()
-{
-    handle = CreateThread(0, 0, &threadFn, this, 0, 0);
-    return handle!=0;
-}
-
-//------------------------------------------------------------------------------
-
-inline void Win32Thread::join()
-{
-    WaitForSingleObject(handle, INFINITE);
-}
-
-//------------------------------------------------------------------------------
-
-} /* namespace xplcommon */
-
-//------------------------------------------------------------------------------
-#endif // HAVE_PTHREAD_H
-
-#endif // XPLCOMMON_POSIXTHREAD_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: src/xplcommon/posix/.copyright
===================================================================
--- src/xplcommon/posix/.copyright	(revision 3)
+++ src/xplcommon/posix/.copyright	(revision 3)
@@ -0,0 +1,23 @@
+// 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.
Index: src/xplcommon/posix/.namespace
===================================================================
--- src/xplcommon/posix/.namespace	(revision 3)
+++ src/xplcommon/posix/.namespace	(revision 3)
@@ -0,0 +1,2 @@
+xplcommon
+posix
Index: src/xplcommon/posix/.srcmessage
===================================================================
--- src/xplcommon/posix/.srcmessage	(revision 3)
+++ src/xplcommon/posix/.srcmessage	(revision 3)
@@ -0,0 +1,2 @@
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
Index: src/xplcommon/posix/Makefile.am
===================================================================
--- src/xplcommon/posix/Makefile.am	(revision 3)
+++ src/xplcommon/posix/Makefile.am	(revision 3)
@@ -0,0 +1,12 @@
+noinst_LTLIBRARIES=libxplcommon_posix.la
+
+libxplcommon_posix_la_SOURCES =	\
+	Thread.cc		\
+	Waitable.cc	\
+	Waiter.cc
+
+include_xplcommon_posixdir=$(includedir)/xplcommon/posix
+include_xplcommon_posix_HEADERS=\
+	Thread.h		\
+	Waitable.h		\
+	Waiter.h
Index: src/xplcommon/posix/Thread.cc
===================================================================
--- src/xplcommon/posix/Thread.cc	(revision 3)
+++ src/xplcommon/posix/Thread.cc	(revision 3)
@@ -0,0 +1,52 @@
+// 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.
+
+//------------------------------------------------------------------------------
+
+#include "Thread.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::posix::Thread;
+
+//------------------------------------------------------------------------------
+
+void* Thread::threadFn(void* arg)
+{
+    reinterpret_cast<Thread*>(arg)->run();
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Thread.h
===================================================================
--- src/xplcommon/posix/Thread.h	(revision 3)
+++ src/xplcommon/posix/Thread.h	(revision 3)
@@ -0,0 +1,115 @@
+// 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_THREAD_H
+#define XPLCOMMON_POSIX_THREAD_H
+//------------------------------------------------------------------------------
+
+#include <pthread.h>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace posix {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A pthreads-based thread implementation.
+ */
+class Thread
+{
+private:
+    /**
+     * The thread-runner function.
+     */
+    static void* threadFn(void* arg);
+
+    /**
+     * The posix thread handle.
+     */
+    pthread_t thread;
+
+public:
+    /**
+     * Virtual destructor.
+     */
+    virtual ~Thread();
+
+    /**
+     * Start the thread.
+     *
+     * @return if the thread could be started
+     */
+    bool start();
+
+    /**
+     * Perform the thread's real operation.
+     */
+    virtual void run() = 0;
+
+    /**
+     * Wait for the thread to quit.
+     */
+    void join();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Thread::~Thread()
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Thread::start()
+{
+    return pthread_create(&thread, 0, &threadFn, this)>=0;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Thread::join()
+{
+    pthread_join(thread, 0);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::posix */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_POSIX_THREAD_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Waitable.cc
===================================================================
--- src/xplcommon/posix/Waitable.cc	(revision 3)
+++ src/xplcommon/posix/Waitable.cc	(revision 3)
@@ -0,0 +1,63 @@
+// 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.
+
+//------------------------------------------------------------------------------
+
+#include "Waitable.h"
+
+#include "Waiter.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::posix::Waitable;
+
+//------------------------------------------------------------------------------
+
+Waitable::Waitable(Waiter* waiter, int fd, short events) :
+    waiter(waiter),
+    fd(fd),
+    events(events)
+{
+    if (waiter!=0) waiter->add(this);
+}
+
+//------------------------------------------------------------------------------
+
+Waitable::~Waitable()
+{
+    if (waiter!=0) waiter->remove(this);
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Waitable.h
===================================================================
--- src/xplcommon/posix/Waitable.h	(revision 3)
+++ src/xplcommon/posix/Waitable.h	(revision 3)
@@ -0,0 +1,106 @@
+// 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_WAITABLE_H
+#define XPLCOMMON_POSIX_WAITABLE_H
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace posix {
+
+//------------------------------------------------------------------------------
+
+class Waiter;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class of objects for which one can wait in a Waiter.
+ *
+ * It is basically a file descriptor.
+ */
+class Waitable
+{
+protected:
+    /**
+     * The waiter this waitable belongs to, if any.
+     */
+    Waiter* waiter;
+
+    /**
+     * The file descriptor
+     */
+    int fd;
+
+    /**
+     * The events this waitable is interested in.
+     */
+    short events;
+
+protected:
+    /**
+     * Construct the waitable.
+     */
+    Waitable(Waiter* waiter, int fd = -1, short events = 0);
+
+public:
+    /**
+     * Destroy the waitable. It will be removed from the waiter.
+     */
+    virtual ~Waitable();
+
+    /**
+     * Indicate if the waitable is ready, i.e. there is no need to
+     * wait for it.
+     *
+     * Calling this function should not deleted the ready
+     * indication. It should be deleted by actually processing the data.
+     */
+    virtual bool ready() = 0;
+
+protected:
+    /**
+     * Handle the given events.
+     */
+    virtual void handleEvents(short events) = 0;
+
+    friend class Waiter;
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::posix */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_POSIXWAITABLE_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Waiter.cc
===================================================================
--- src/xplcommon/posix/Waiter.cc	(revision 3)
+++ src/xplcommon/posix/Waiter.cc	(revision 3)
@@ -0,0 +1,153 @@
+// 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.
+
+//------------------------------------------------------------------------------
+
+#include "Waiter.h"
+
+#include "Waitable.h"
+
+#include <cassert>
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using xplcommon::posix::Waiter;
+
+//------------------------------------------------------------------------------
+
+inline bool Waiter::hasReady() const
+{
+    for(waitables_t::const_iterator i = waitables.begin(); i!=waitables.end();
+        ++i)
+    {
+        Waitable* waitable = i->second;
+        if (waitable->ready()) return true;
+    }
+    return false;
+}
+
+//------------------------------------------------------------------------------
+
+inline size_t Waiter::setupPollFDs(pollfd* pollFDs)
+{
+    size_t numValid = 0;
+
+    for(waitables_t::const_iterator i = waitables.begin(); i!=waitables.end();
+        ++i)
+    {
+        Waitable* waitable = i->second;
+        if (waitable->events==0) continue;
+
+        pollfd& pollFD = pollFDs[numValid++];
+
+        pollFD.fd = waitable->fd;
+        pollFD.events = waitable->events;
+        pollFD.revents = 0;
+    }
+
+    return numValid;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Waiter::processPollFDs(const pollfd* pollFDs, size_t size)
+{
+    for(size_t i = 0; i<size; ++i) {
+        const pollfd& pollFD = pollFDs[i];
+        if (pollFD.revents!=0) {
+            waitables_t::iterator j = waitables.find(pollFD.fd);
+            assert(j!=waitables.end());
+            Waitable* waitable = j->second;
+            waitable->handleEvents(pollFD.revents);
+        }
+    }
+}
+
+//------------------------------------------------------------------------------
+
+Waiter::~Waiter()
+{
+    for(waitables_t::iterator i = waitables.begin(); i!=waitables.end(); ++i)
+    {
+        Waitable* waitable = i->second;
+        waitable->waiter = 0;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+bool Waiter::wait(int timeout)
+{
+    if (hasReady()) return true;
+
+    pollfd pollFDs[numWaitables];
+    size_t numValid = setupPollFDs(pollFDs);
+
+    int result = poll(pollFDs, numValid, timeout);
+
+    if (result<0) {
+        perror("xplcommon::posix::Waiter::wait: poll");
+        return false;
+    } else if (result>0) {
+        processPollFDs(pollFDs, numValid);
+    }
+
+    return hasReady();
+}
+
+//------------------------------------------------------------------------------
+
+void Waiter::add(Waitable* waitable)
+{
+    assert(waitable->fd>=0);
+    assert(waitables.find(waitable->fd)==waitables.end());
+    waitables[waitable->fd] = waitable;
+    ++numWaitables;
+}
+
+//------------------------------------------------------------------------------
+
+void Waiter::remove(Waitable* waitable)
+{
+    assert(numWaitables>0);
+    assert(waitables.find(waitable->fd)!=waitables.end());
+    assert(waitables[waitable->fd]==waitable);
+    waitables.erase(waitable->fd);
+    --numWaitables;
+}
+
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Waiter.h
===================================================================
--- src/xplcommon/posix/Waiter.h	(revision 3)
+++ src/xplcommon/posix/Waiter.h	(revision 3)
@@ -0,0 +1,153 @@
+// 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_WAITER_H
+#define XPLCOMMON_POSIX_WAITER_H
+//------------------------------------------------------------------------------
+
+#include <map>
+
+#include <cstdlib>
+
+#include <poll.h>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace posix {
+
+//------------------------------------------------------------------------------
+
+class Waitable;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Class that can be used to register waitable objects and then wait
+ * for them.
+ */
+class Waiter
+{
+private:
+    /**
+     * Type for the set of waitables.
+     */
+    typedef std::map<int, Waitable*> waitables_t;
+
+    /**
+     * The set of waitables belonging to this waiter.
+     */
+    waitables_t waitables;
+
+    /**
+     * The number of waitables.
+     */
+    size_t numWaitables;
+
+public:
+    /**
+     * Construct the waiter.
+     */
+    Waiter();
+
+    /**
+     * Destroy the waiter. All waitables that still exists will be
+     * modified to point to no waiter.
+     */
+    ~Waiter();
+
+    /**
+     * Wait for any if the waitables to become ready or until a
+     * timeout expires.
+     *
+     * If any of the waitables are ready, the function returns immediately.
+     *
+     * @return true if any of the waitables has become ready, false if
+     * the timeout occurs.
+     */
+    bool wait(int timeout = -1);
+
+protected:
+    /**
+     * Add a waitable.
+     */
+    void add(Waitable* waitable);
+
+    /**
+     * Remove a waitable.
+     */
+    void remove(Waitable* waitable);
+
+private:
+    /**
+     * Determine if any of the waitables is ready.
+     */
+    bool hasReady() const;
+
+    /**
+     * Fill the given array of poll descriptors with those file
+     * descriptors that wait for an event.
+     *
+     * @param pollFDs the file descriptor array to fill. It should
+     * contain at least as many elements as the number of waitables.
+     *
+     * @return the number of valid poll file descriptors.
+     */
+    size_t setupPollFDs(pollfd* pollFDs);
+
+    /**
+     * Process the given array of poll descriptors. For each
+     * descriptor, if its events are not 0, the handleEvents()
+     * function of the corresponding waitable is called.
+     */
+    void processPollFDs(const pollfd* pollFDs, size_t size);
+
+    friend class Waitable;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Waiter::Waiter() :
+    numWaitables(0)
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::posix */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_POSIX_WAITABLE_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/.copyright
===================================================================
--- src/xplcommon/win32/.copyright	(revision 3)
+++ src/xplcommon/win32/.copyright	(revision 3)
@@ -0,0 +1,23 @@
+// 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.
Index: src/xplcommon/win32/.namespace
===================================================================
--- src/xplcommon/win32/.namespace	(revision 3)
+++ src/xplcommon/win32/.namespace	(revision 3)
@@ -0,0 +1,2 @@
+xplcommon
+win32
Index: src/xplcommon/win32/.srcmessage
===================================================================
--- src/xplcommon/win32/.srcmessage	(revision 3)
+++ src/xplcommon/win32/.srcmessage	(revision 3)
@@ -0,0 +1,2 @@
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
Index: src/xplcommon/win32/Makefile.am
===================================================================
--- src/xplcommon/win32/Makefile.am	(revision 3)
+++ src/xplcommon/win32/Makefile.am	(revision 3)
@@ -0,0 +1,8 @@
+noinst_LTLIBRARIES=libxplcommon_win32.la
+
+libxplcommon_win32_la_SOURCES =	\
+	Thread.cc
+
+include_xplcommon_win32dir=$(includedir)/xplcommon/win32
+include_xplcommon_win32_HEADERS=\
+	Thread.h
Index: src/xplcommon/win32/Thread.cc
===================================================================
--- src/xplcommon/win32/Thread.cc	(revision 3)
+++ src/xplcommon/win32/Thread.cc	(revision 3)
@@ -0,0 +1,52 @@
+// 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.
+
+//------------------------------------------------------------------------------
+
+#include "Thread.h"
+
+//------------------------------------------------------------------------------
+
+using xplcommon::win32::Thread;
+
+//------------------------------------------------------------------------------
+
+DWORD Thread::threadFn(LPVOID arg)
+{
+    reinterpret_cast<Thread*>(arg)->run();
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/win32/Thread.h
===================================================================
--- src/xplcommon/win32/Thread.h	(revision 3)
+++ src/xplcommon/win32/Thread.h	(revision 3)
@@ -0,0 +1,116 @@
+// 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_THREAD_H
+#define XPLCOMMON_WIN32_THREAD_H
+//------------------------------------------------------------------------------
+
+#include <windows.h>
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace win32 {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A Win32 API thread implementation.
+ */
+class Thread
+{
+private:
+    /**
+     * The thread-runner function.
+     */
+    static DWORD WINAPI threadFn(LPVOID arg);
+
+    /**
+     * The thread handle.
+     */
+    HANDLE handle;
+
+public:
+    /**
+     * Virtual destructor.
+     */
+    virtual ~Thread();
+
+    /**
+     * Start the thread.
+     *
+     * @return if the thread could be started
+     */
+    bool start();
+
+    /**
+     * Perform the thread's real operation.
+     */
+    virtual void run() = 0;
+
+    /**
+     * Wait for the thread to quit.
+     */
+    void join();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Thread::~Thread()
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Thread::start()
+{
+    handle = CreateThread(0, 0, &threadFn, this, 0, 0);
+    return handle!=0;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Thread::join()
+{
+    WaitForSingleObject(handle, INFINITE);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::win32 */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WIN32_THREAD_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
