]> granicus.if.org Git - icinga2/commitdiff
Use InterlockedIncrement instead of a mutex in CreatePipeOverlapped
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 11 Aug 2016 07:43:50 +0000 (09:43 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 11 Aug 2016 07:48:01 +0000 (09:48 +0200)
refs #10075

lib/base/process.cpp

index 76628cce28d82f18876ad8cc700beaa00e5dc407..5a522e09d9402df47b165cc03ec32f1a1472f008 100644 (file)
@@ -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);