From 2e4f8bfdb1be9d24347d2c71f80785aef4eff824 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Sat, 30 Jul 2005 19:03:34 +0000 Subject: [PATCH] If a mutex already exist, open it instead of create. svn path=/trunk/; revision=16901 --- reactos/lib/kernel32/synch/mutex.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/reactos/lib/kernel32/synch/mutex.c b/reactos/lib/kernel32/synch/mutex.c index 854901d3a9e..9752796251a 100644 --- a/reactos/lib/kernel32/synch/mutex.c +++ b/reactos/lib/kernel32/synch/mutex.c @@ -92,10 +92,24 @@ CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, MUTEX_ALL_ACCESS, &ObjectAttributes, (BOOLEAN)bInitialOwner); + if (Status == STATUS_OBJECT_NAME_COLLISION) + { + Status = NtOpenMutant(&MutantHandle, + MUTEX_ALL_ACCESS, + &ObjectAttributes); + if (NT_SUCCESS(Status)) + { + if(bInitialOwner) + { + WaitForSingleObject(MutantHandle, INFINITE); + } + SetLastError(ERROR_ALREADY_EXISTS); + } + } if (!NT_SUCCESS(Status)) { - SetLastErrorByStatus(Status); - return NULL; + SetLastErrorByStatus(Status); + return NULL; } return MutantHandle;