mirror of
https://github.com/winfsp/winfsp.git
synced 2025-06-16 00:32:46 -05:00
dll: convert all initialization to the initonce pattern
This commit is contained in:
21
src/dll/fs.c
21
src/dll/fs.c
@ -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;
|
||||
|
Reference in New Issue
Block a user