From c205570127c9f35607e55e96c4a2fac4c2553e99 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 27 Apr 2015 17:19:26 +0000 Subject: Make an RAII com initializer. Differential Revision: http://reviews.llvm.org/D9267 Reviewed By: Aaron Ballman, David Majnemer llvm-svn: 235898 --- llvm/lib/Support/Windows/COM.inc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 llvm/lib/Support/Windows/COM.inc (limited to 'llvm/lib/Support/Windows') 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 + +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(); } +} +} -- cgit v1.2.3