dll: convert all initialization to the initonce pattern

This commit is contained in:
Bill Zissimopoulos
2016-06-16 12:17:38 -07:00
parent b695ef8ad8
commit 68d79b0c3b
13 changed files with 53 additions and 124 deletions

View File

@ -24,20 +24,16 @@ enum
static FSP_FILE_SYSTEM_INTERFACE FspFileSystemNullInterface;
static INIT_ONCE FspFileSystemInitOnce = INIT_ONCE_STATIC_INIT;
static BOOLEAN FspFileSystemInitialized;
static CRITICAL_SECTION FspFileSystemMountListGuard;
static LIST_ENTRY FspFileSystemMountList = { &FspFileSystemMountList, &FspFileSystemMountList };
VOID FspFileSystemInitialize(BOOLEAN Dynamic)
static BOOL WINAPI FspFileSystemInitialize(
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
{
/*
* This function is called during DLL_PROCESS_ATTACH. We must therefore keep
* initialization tasks to a minimum.
*
* Initialization of synchronization objects is allowed! See:
* https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
*/
InitializeCriticalSection(&FspFileSystemMountListGuard);
return FspFileSystemInitialized = TRUE;
}
VOID FspFileSystemFinalize(BOOLEAN Dynamic)
@ -60,6 +56,9 @@ VOID FspFileSystemFinalize(BOOLEAN Dynamic)
* OS will clean it up for us.
*/
if (!FspFileSystemInitialized)
return;
FSP_FILE_SYSTEM *FileSystem;
PLIST_ENTRY MountEntry;
@ -95,6 +94,10 @@ FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath,
if (0 == Interface)
Interface = &FspFileSystemNullInterface;
InitOnceExecuteOnce(&FspFileSystemInitOnce, FspFileSystemInitialize, 0, 0);
if (!FspFileSystemInitialized)
return STATUS_INSUFFICIENT_RESOURCES;
FileSystem = MemAlloc(sizeof *FileSystem);
if (0 == FileSystem)
return STATUS_INSUFFICIENT_RESOURCES;