[Lldb-commits] [PATCH] Implements a HostThread class.

Bruce Mitchener bruce.mitchener at gmail.com
Thu Aug 28 20:53:32 PDT 2014


One approach that I've seen for this in games where virtual function calls
are an unhappy thing is a pattern where the inheritance appears to be
inverted:

In this case, you'd have each platform class in their own files and
directory structure:

    class HostThreadMacOSX { ... };

    class HostThreadWindows { ... };

Then, you'd have a single HostThread.h that looked roughly like:

    if (__WIN32__)
    #include "threading/windows/HostThreadWindows.h"

    namespace lldb
    {
    class HostThread : public Windows::HostThreadWindows
    {
    };
    }
    #elif __APPLE__
    #include "threading/macosx/HostThreadMacOSX.h"
    namespace lldb
    {
    class HostThread : public MacOSX::HostThreadMacOSX
    {
    };
    }
    #else
    #error "lldb::HostThread not implemented on this platform!"
    #endif

Now, all of the code can reference HostThread, there are no virtual calls,
and each platform can invoke platform-specific behavior with ease.

It has some downsides, like the exact interface of what is required isn't
as clear (since there's no "interface" class), but I've had good luck with
this structure in the past.

Hope this is interesting / useful!

 - Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140829/3ba5c72b/attachment.html>


More information about the lldb-commits mailing list