summaryrefslogtreecommitdiff
path: root/include/lldb/Host/windows/AutoHandle.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Host/windows/AutoHandle.h')
-rw-r--r--include/lldb/Host/windows/AutoHandle.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/lldb/Host/windows/AutoHandle.h b/include/lldb/Host/windows/AutoHandle.h
new file mode 100644
index 000000000000..04411c47d9e2
--- /dev/null
+++ b/include/lldb/Host/windows/AutoHandle.h
@@ -0,0 +1,40 @@
+//===-- AutoHandle.h --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_lldb_Host_windows_AutoHandle_h_
+#define LLDB_lldb_Host_windows_AutoHandle_h_
+
+namespace lldb_private {
+
+class AutoHandle {
+public:
+ AutoHandle(HANDLE handle, HANDLE invalid_value = INVALID_HANDLE_VALUE)
+ : m_handle(handle)
+ , m_invalid_value(invalid_value)
+ {
+ }
+
+ ~AutoHandle()
+ {
+ if (m_handle != m_invalid_value)
+ ::CloseHandle(m_handle);
+ }
+
+ bool IsValid() const { return m_handle != m_invalid_value; }
+
+ HANDLE get() const { return m_handle; }
+private:
+ HANDLE m_handle;
+ HANDLE m_invalid_value;
+};
+
+}
+
+#endif
+