diff --git a/win32ss/gdi/eng/device.c b/win32ss/gdi/eng/device.c index 8a0d686d2ea..1e2a46a0a17 100644 --- a/win32ss/gdi/eng/device.c +++ b/win32ss/gdi/eng/device.c @@ -98,6 +98,36 @@ EngpHasVgaDriver( return (_wcsnicmp(awcServiceName, L"VGA", 3) == 0); } +/* + * Add a device to gpGraphicsDeviceFirst/gpGraphicsDeviceLast list (if not already present). + */ +_Requires_lock_held_(ghsemGraphicsDeviceList) +static +VOID +EngpLinkGraphicsDevice( + _In_ PGRAPHICS_DEVICE pToAdd) +{ + PGRAPHICS_DEVICE pGraphicsDevice; + + TRACE("EngLinkGraphicsDevice(%p)\n", pToAdd); + + /* Search if device is not already linked */ + for (pGraphicsDevice = gpGraphicsDeviceFirst; + pGraphicsDevice; + pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice) + { + if (pGraphicsDevice == pToAdd) + return; + } + + pToAdd->pNextGraphicsDevice = NULL; + if (gpGraphicsDeviceLast) + gpGraphicsDeviceLast->pNextGraphicsDevice = pToAdd; + gpGraphicsDeviceLast = pToAdd; + if (!gpGraphicsDeviceFirst) + gpGraphicsDeviceFirst = pToAdd; +} + /* * Remove a device from gpGraphicsDeviceFirst/gpGraphicsDeviceLast list. */ @@ -567,12 +597,7 @@ EngpRegisterGraphicsDevice( EngAcquireSemaphore(ghsemGraphicsDeviceList); /* Insert the device into the global list */ - pGraphicsDevice->pNextGraphicsDevice = NULL; - if (gpGraphicsDeviceLast) - gpGraphicsDeviceLast->pNextGraphicsDevice = pGraphicsDevice; - gpGraphicsDeviceLast = pGraphicsDevice; - if (!gpGraphicsDeviceFirst) - gpGraphicsDeviceFirst = pGraphicsDevice; + EngpLinkGraphicsDevice(pGraphicsDevice); /* Increment the device number */ giDevNum++;