[icinga-checkins] icinga.org: icinga2/master: Use InterlockedIncrement instead of a mutex in CreatePipeOverlapped

git at icinga.org git at icinga.org
Thu Aug 11 09:48:04 CEST 2016


Module: icinga2
Branch: master
Commit: 132ee6c558dd806ff785b12b0e051db4dad932e2
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=132ee6c558dd806ff785b12b0e051db4dad932e2

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Aug 11 09:43:50 2016 +0200

Use InterlockedIncrement instead of a mutex in CreatePipeOverlapped

refs #10075

---

 lib/base/process.cpp |   13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/lib/base/process.cpp b/lib/base/process.cpp
index 76628cc..5a522e0 100644
--- a/lib/base/process.cpp
+++ b/lib/base/process.cpp
@@ -323,22 +323,15 @@ String Process::PrettyPrintArguments(const Process::Arguments& arguments)
 static BOOL CreatePipeOverlapped(HANDLE *outReadPipe, HANDLE *outWritePipe,
     SECURITY_ATTRIBUTES *securityAttributes, DWORD size, DWORD readMode, DWORD writeMode)
 {
-	static int pipeIndex = 0;
-	static boost::mutex mutex;
+	static LONG pipeIndex = 0;
 
 	if (size == 0)
 		size = 8192;
 
-	int currentIndex;
-
-	{
-		boost::mutex::scoped_lock lock(mutex);
-		currentIndex = pipeIndex;
-		pipeIndex++;
-	}
+	LONG currentIndex = InterlockedIncrement(&pipeIndex);
 
 	char pipeName[128];
-	sprintf(pipeName, "\\\\.\\Pipe\\OverlappedPipe.%d.%d", (int)GetCurrentProcessId(), currentIndex);
+	sprintf(pipeName, "\\\\.\\Pipe\\OverlappedPipe.%d.%d", (int)GetCurrentProcessId(), (int)currentIndex);
 
 	*outReadPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_INBOUND | readMode,
 	    PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size, 60 * 1000, securityAttributes);



More information about the icinga-checkins mailing list