summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-04-27 17:19:26 +0000
committerZachary Turner <zturner@google.com>2015-04-27 17:19:26 +0000
commitc205570127c9f35607e55e96c4a2fac4c2553e99 (patch)
tree3915f9f2683dffdcca3549d6f94c04bbe5c82b1f
parent035025c0da0bbcd987093187b23ccd284d0942d9 (diff)
downloadbcm5719-llvm-c205570127c9f35607e55e96c4a2fac4c2553e99.tar.gz
bcm5719-llvm-c205570127c9f35607e55e96c4a2fac4c2553e99.zip
Make an RAII com initializer.
Differential Revision: http://reviews.llvm.org/D9267 Reviewed By: Aaron Ballman, David Majnemer llvm-svn: 235898
-rw-r--r--llvm/include/llvm/Support/COM.h36
-rw-r--r--llvm/lib/Support/CMakeLists.txt1
-rw-r--r--llvm/lib/Support/COM.cpp23
-rw-r--r--llvm/lib/Support/Unix/COM.inc27
-rw-r--r--llvm/lib/Support/Windows/COM.inc37
5 files changed, 124 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/COM.h b/llvm/include/llvm/Support/COM.h
new file mode 100644
index 00000000000..a2d5a7a68ba
--- /dev/null
+++ b/llvm/include/llvm/Support/COM.h
@@ -0,0 +1,36 @@
+//===- llvm/Support/COM.h ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+///
+/// Provides a library for accessing COM functionality of the Host OS.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_COM_H
+#define LLVM_SUPPORT_COM_H
+
+namespace llvm {
+namespace sys {
+
+enum class COMThreadingMode { SingleThreaded, MultiThreaded };
+
+class InitializeCOMRAII {
+public:
+ explicit InitializeCOMRAII(COMThreadingMode Threading,
+ bool SpeedOverMemory = false);
+ ~InitializeCOMRAII();
+
+private:
+ InitializeCOMRAII(const InitializeCOMRAII &) = delete;
+ void operator=(const InitializeCOMRAII &) = delete;
+};
+}
+}
+
+#endif
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 684afa95578..a91600fc4dd 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -37,6 +37,7 @@ add_llvm_library(LLVMSupport
BlockFrequency.cpp
BranchProbability.cpp
circular_raw_ostream.cpp
+ COM.cpp
CommandLine.cpp
Compression.cpp
ConvertUTF.c
diff --git a/llvm/lib/Support/COM.cpp b/llvm/lib/Support/COM.cpp
new file mode 100644
index 00000000000..cf3a133fd9b
--- /dev/null
+++ b/llvm/lib/Support/COM.cpp
@@ -0,0 +1,23 @@
+//===-- COM.cpp - Implement COM utility classes -----------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements utility classes related to COM.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/COM.h"
+
+#include "llvm/Config/config.h"
+
+// Include the platform-specific parts of this class.
+#ifdef LLVM_ON_UNIX
+#include "Unix/COM.inc"
+#elif LLVM_ON_WIN32
+#include "Windows/COM.inc"
+#endif
diff --git a/llvm/lib/Support/Unix/COM.inc b/llvm/lib/Support/Unix/COM.inc
new file mode 100644
index 00000000000..c7b930b4283
--- /dev/null
+++ b/llvm/lib/Support/Unix/COM.inc
@@ -0,0 +1,27 @@
+//===- llvm/Support/Unix/COM.inc - Unix COM Implementation -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Unix portion of COM support.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only generic UNIX code that
+//=== is guaranteed to work on *all* UNIX variants.
+//===----------------------------------------------------------------------===//
+
+namespace llvm {
+namespace sys {
+
+COMInitializer::COMInitializer(COMThreadingMode Threading,
+ bool SpeedOverMemory) {}
+
+COMInitializer::~COMInitializer() {}
+}
+}
diff --git a/llvm/lib/Support/Windows/COM.inc b/llvm/lib/Support/Windows/COM.inc
new file mode 100644
index 00000000000..0c50d6f74ea
--- /dev/null
+++ b/llvm/lib/Support/Windows/COM.inc
@@ -0,0 +1,37 @@
+//===- llvm/Support/Windows/COM.inc - Windows COM Implementation *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Windows portion of COM support.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Windows code.
+//===----------------------------------------------------------------------===//
+
+#include <objbase.h>
+
+namespace llvm {
+namespace sys {
+
+InitializeCOMRAII::InitializeCOMRAII(COMThreadingMode Threading,
+ bool SpeedOverMemory) {
+ DWORD Coinit = 0;
+ if (Threading == COMThreadingMode::SingleThreaded)
+ Coinit |= COINIT_APARTMENTTHREADED;
+ else
+ Coinit |= COINIT_MULTITHREADED;
+ if (SpeedOverMemory)
+ Coinit |= COINIT_SPEED_OVER_MEMORY;
+ ::CoInitializeEx(nullptr, Coinit);
+}
+
+InitializeCOMRAII::~InitializeCOMRAII() { ::CoUninitialize(); }
+}
+}
OpenPOWER on IntegriCloud