aboutsummaryrefslogtreecommitdiff
path: root/butl/process-details
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-03-18 00:55:59 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-03-20 17:24:38 +0300
commitaa5ce03b40003ee8f7cfff4d2f1285b405f5906a (patch)
tree29d4131e644554e2dbe38c1ed84e4847467ff5b7 /butl/process-details
parentd13eb80e2f4114a97c523a7273d7de4c587dd22a (diff)
Fix file descriptors leakage to child process on Windows
Diffstat (limited to 'butl/process-details')
-rw-r--r--butl/process-details49
1 files changed, 49 insertions, 0 deletions
diff --git a/butl/process-details b/butl/process-details
new file mode 100644
index 0000000..b07ceff
--- /dev/null
+++ b/butl/process-details
@@ -0,0 +1,49 @@
+// file : butl/process-details -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BUTL_PROCESS_DETAILS
+#define BUTL_PROCESS_DETAILS
+
+#include <mutex>
+
+#include <butl/ft/shared_mutex>
+#if defined(__cpp_lib_shared_mutex) || defined(__cpp_lib_shared_timed_mutex)
+# include <shared_mutex>
+#endif
+
+namespace butl
+{
+#if defined(__cpp_lib_shared_mutex)
+ using shared_mutex = std::shared_mutex;
+ using ulock = std::unique_lock<shared_mutex>;
+ using slock = std::shared_lock<shared_mutex>;
+#elif defined(__cpp_lib_shared_timed_mutex)
+ using shared_mutex = std::shared_timed_mutex;
+ using ulock = std::unique_lock<shared_mutex>;
+ using slock = std::shared_lock<shared_mutex>;
+#else
+ // Because we have this fallback, we need to be careful not to create
+ // multiple shared locks in the same thread.
+ //
+ struct shared_mutex: std::mutex
+ {
+ using mutex::mutex;
+
+ void lock_shared () { lock (); }
+ void try_lock_shared () { try_lock (); }
+ void unlock_shared () { unlock (); }
+ };
+
+ using ulock = std::unique_lock<shared_mutex>;
+ using slock = ulock;
+#endif
+
+ // Mutex that is acquired to make a sequence of operations atomic in regards
+ // to child process spawning. Must be aquired for exclusive access for child
+ // process startup, and for shared access otherwise. Defined in process.cxx.
+ //
+ extern shared_mutex process_spawn_mutex;
+}
+
+#endif // BUTL_PROCESS_DETAILS