[Lldb-commits] [PATCH] Implements a HostThread class.
Zachary Turner
zturner at google.com
Thu Aug 28 20:54:46 PDT 2014
That's actually exactly what I've done! Check the code in HostThread.h in
the original patch. The difference is that instead of empty inheritance, I
used a typedef. But the idea is exactly the same.
On Thu, Aug 28, 2014 at 8:53 PM, Bruce Mitchener <bruce.mitchener at gmail.com>
wrote:
> 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/20140828/b8d4c096/attachment.html>
More information about the lldb-commits
mailing list