typedef struct _COMDB
{
+ HANDLE hMutex;
HKEY hKey;
} COMDB, *PCOMDB;
pComDB = (PCOMDB)hComDB;
+ /* Wait for the mutex */
+ WaitForSingleObject(pComDB->hMutex, INFINITE);
+
/* Get the required bitmap size */
lError = RegQueryValueExW(pComDB->hKey,
L"ComDB",
NULL,
&dwSize);
if (lError != ERROR_SUCCESS)
- return lError;
+ {
+ ERR("Failed to query the bitmap size!\n");
+ goto done;
+ }
/* Allocate the bitmap */
pBitmap = HeapAlloc(GetProcessHeap(),
if (pBitmap == NULL)
{
ERR("Failed to allocate the bitmap!\n");
- return lError;
+ lError = ERROR_NOT_ENOUGH_MEMORY;
+ goto done;
}
/* Read the bitmap */
}
done:;
+ /* Release the mutex */
+ ReleaseMutex(pComDB->hMutex);
+
+ /* Release the bitmap */
if (pBitmap != NULL)
HeapFree(GetProcessHeap(), 0, pBitmap);
pComDB = (PCOMDB)hComDB;
+ /* Wait for the mutex */
+ WaitForSingleObject(pComDB->hMutex, INFINITE);
+
/* Get the required bitmap size */
lError = RegQueryValueExW(pComDB->hKey,
L"ComDB",
NULL,
&dwSize);
if (lError != ERROR_SUCCESS)
- return lError;
+ {
+ ERR("Failed to query the bitmap size!\n");
+ goto done;
+ }
/* Allocate the bitmap */
pBitmap = HeapAlloc(GetProcessHeap(),
if (pBitmap == NULL)
{
ERR("Failed to allocate the bitmap!\n");
- return lError;
+ lError = ERROR_NOT_ENOUGH_MEMORY;
+ goto done;
}
/* Read the bitmap */
}
done:
+ /* Release the mutex */
+ ReleaseMutex(pComDB->hMutex);
+
+ /* Release the bitmap */
if (pBitmap != NULL)
HeapFree(GetProcessHeap(), 0, pBitmap);
TRACE("ComDBClose(%p)\n", hComDB);
- if (hComDB == HCOMDB_INVALID_HANDLE_VALUE || hComDB == NULL)
+ if (hComDB == HCOMDB_INVALID_HANDLE_VALUE ||
+ hComDB == NULL)
return ERROR_INVALID_PARAMETER;
pComDB = (PCOMDB)hComDB;
if (pComDB->hKey != NULL)
RegCloseKey(pComDB->hKey);
+ /* Close the mutex */
+ if (pComDB->hMutex != NULL)
+ CloseHandle(pComDB->hMutex);
+
/* Release the database */
HeapFree(GetProcessHeap(), 0, pComDB);
if (pComDB == NULL)
{
ERR("Failed to allocate the database!\n");
+ *phComDB = HCOMDB_INVALID_HANDLE_VALUE;
return ERROR_ACCESS_DENIED;
}
+ /* Create a mutex to protect the database */
+ pComDB->hMutex = CreateMutexW(NULL,
+ FALSE,
+ L"ComDBMutex");
+ if (pComDB->hMutex == NULL)
+ {
+ ERR("Failed to create the mutex!\n");
+ HeapFree(GetProcessHeap(), 0, pComDB);
+ *phComDB = HCOMDB_INVALID_HANDLE_VALUE;
+ return ERROR_ACCESS_DENIED;
+ }
+
+ /* Wait for the mutex */
+ WaitForSingleObject(pComDB->hMutex, INFINITE);
+
/* Create or open the database key */
lError = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
L"System\\CurrentControlSet\\Control\\COM Name Arbiter",
}
done:;
+ /* Release the mutex */
+ ReleaseMutex(pComDB->hMutex);
+
if (lError != ERROR_SUCCESS)
{
/* Clean up in case of failure */
if (pComDB->hKey != NULL)
RegCloseKey(pComDB->hKey);
+ if (pComDB->hMutex != NULL)
+ CloseHandle(pComDB->hMutex);
+
HeapFree(GetProcessHeap(), 0, pComDB);
*phComDB = HCOMDB_INVALID_HANDLE_VALUE;
pComDB = (PCOMDB)hComDB;
+ /* Wait for the mutex */
+ WaitForSingleObject(pComDB->hMutex, INFINITE);
+
/* Get the required bitmap size */
lError = RegQueryValueExW(pComDB->hKey,
L"ComDB",
NULL,
&dwSize);
if (lError != ERROR_SUCCESS)
- return lError;
+ {
+ ERR("Failed to query the bitmap size!\n");
+ goto done;
+ }
/* Allocate the bitmap */
pBitmap = HeapAlloc(GetProcessHeap(),
if (pBitmap == NULL)
{
ERR("Failed to allocate the bitmap!\n");
- return lError;
+ lError = ERROR_NOT_ENOUGH_MEMORY;
+ goto done;
}
/* Read the bitmap */
dwSize);
done:;
+ /* Release the mutex */
+ ReleaseMutex(pComDB->hMutex);
+
+ /* Release the bitmap */
if (pBitmap != NULL)
HeapFree(GetProcessHeap(), 0, pBitmap);