[1/3] winebus.sys: Spawn a device loop thread and add synchronization.

Aric Stewart aric at codeweavers.com
Mon Oct 3 10:29:41 CDT 2016


Signed-off-by: Aric Stewart <aric at codeweavers.com>

On 10/3/16 6:24 AM, Sebastian Lackner wrote:
> Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
> ---
> 
> Alexandres remark that we should probably build the initial deviceset from
> the monitor thread is valid, and I have also thought about that in the past.
> Nevertheless, I think it is a good idea to have some synchronization at least,
> so that we do not proceed with the execution until we are done with the
> initialization.
> 
>  dlls/winebus.sys/bus_udev.c |   38 ++++++++++++++++++++++++++++++++++++--
>  1 file changed, 36 insertions(+), 2 deletions(-)
> 
> diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c
> index 1525861..1f6df6f 100644
> --- a/dlls/winebus.sys/bus_udev.c
> +++ b/dlls/winebus.sys/bus_udev.c
> @@ -164,8 +164,21 @@ static void build_initial_deviceset(void)
>      udev_enumerate_unref(enumerate);
>  }
>  
> +static DWORD CALLBACK deviceloop_thread(void *args)
> +{
> +    HANDLE init_done = args;
> +
> +    build_initial_deviceset();
> +    SetEvent(init_done);
> +
> +    return 0;
> +}
> +
>  NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
>  {
> +    HANDLE events[2];
> +    DWORD result;
> +
>      TRACE("(%p, %s)\n", driver, debugstr_w(registry_path->Buffer));
>  
>      if (!(udev_context = udev_new()))
> @@ -177,8 +190,29 @@ NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry
>      udev_driver_obj = driver;
>      driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
>  
> -    build_initial_deviceset();
> -    return STATUS_SUCCESS;
> +    if (!(events[0] = CreateEventW(NULL, TRUE, FALSE, NULL)))
> +        goto error;
> +    if (!(events[1] = CreateThread(NULL, 0, deviceloop_thread, events[0], 0, NULL)))
> +    {
> +        CloseHandle(events[0]);
> +        goto error;
> +    }
> +
> +    result = WaitForMultipleObjects(2, events, FALSE, INFINITE);
> +    CloseHandle(events[0]);
> +    CloseHandle(events[1]);
> +    if (result == WAIT_OBJECT_0)
> +    {
> +        TRACE("Initialization successful\n");
> +        return STATUS_SUCCESS;
> +    }
> +
> +error:
> +    ERR("Failed to initialize udev device thread\n");
> +    udev_unref(udev_context);
> +    udev_context = NULL;
> +    udev_driver_obj = NULL;
> +    return STATUS_UNSUCCESSFUL;
>  }
>  
>  #else
> 



More information about the wine-patches mailing list