[PATCH 1/5] winepulse: Use event handle to signal main loop readyness.

Andrew Eikum aeikum at codeweavers.com
Thu May 27 14:32:19 CDT 2021


Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>

On Wed, May 26, 2021 at 04:18:36PM +0200, Jacek Caban wrote:
> Signed-off-by: Jacek Caban <jacek at codeweavers.com>
> ---
>  dlls/winepulse.drv/mmdevdrv.c | 12 ++++++++----
>  dlls/winepulse.drv/pulse.c    |  7 +++----
>  dlls/winepulse.drv/unixlib.h  |  3 +--
>  3 files changed, 12 insertions(+), 10 deletions(-)
> 
> 

> diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
> index bc28bce137e..1a39db0f72b 100644
> --- a/dlls/winepulse.drv/mmdevdrv.c
> +++ b/dlls/winepulse.drv/mmdevdrv.c
> @@ -193,8 +193,9 @@ static inline ACImpl *impl_from_IAudioStreamVolume(IAudioStreamVolume *iface)
>      return CONTAINING_RECORD(iface, ACImpl, IAudioStreamVolume_iface);
>  }
>  
> -static DWORD CALLBACK pulse_mainloop_thread(void *tmp) {
> -    pulse->main_loop();
> +static DWORD CALLBACK pulse_mainloop_thread(void *event)
> +{
> +    pulse->main_loop(event);
>      return 0;
>  }
>  
> @@ -557,14 +558,17 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
>  
>      if (!pulse_thread)
>      {
> -        if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, NULL, 0, NULL)))
> +        HANDLE event = CreateEventW(NULL, TRUE, FALSE, NULL);
> +        if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, event, 0, NULL)))
>          {
>              ERR("Failed to create mainloop thread.\n");
>              pulse->unlock();
> +            CloseHandle(event);
>              return E_FAIL;
>          }
>          SetThreadPriority(pulse_thread, THREAD_PRIORITY_TIME_CRITICAL);
> -        pulse->cond_wait();
> +        WaitForSingleObject(event, INFINITE);
> +        CloseHandle(event);
>      }
>  
>      name = get_application_name();
> diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c
> index 05e1dacd68e..143406988d4 100644
> --- a/dlls/winepulse.drv/pulse.c
> +++ b/dlls/winepulse.drv/pulse.c
> @@ -109,7 +109,7 @@ static void WINAPI pulse_unlock(void)
>      pthread_mutex_unlock(&pulse_mutex);
>  }
>  
> -static int WINAPI pulse_cond_wait(void)
> +static int pulse_cond_wait(void)
>  {
>      return pthread_cond_wait(&pulse_cond, &pulse_mutex);
>  }
> @@ -175,13 +175,13 @@ static int pulse_poll_func(struct pollfd *ufds, unsigned long nfds, int timeout,
>      return r;
>  }
>  
> -static void WINAPI pulse_main_loop(void)
> +static void WINAPI pulse_main_loop(HANDLE event)
>  {
>      int ret;
>      pulse_ml = pa_mainloop_new();
>      pa_mainloop_set_poll_func(pulse_ml, pulse_poll_func, NULL);
> +    NtSetEvent(event, NULL);
>      pulse_lock();
> -    pulse_broadcast();
>      pa_mainloop_run(pulse_ml, &ret);
>      pulse_unlock();
>      pa_mainloop_free(pulse_ml);
> @@ -1809,7 +1809,6 @@ static const struct unix_funcs unix_funcs =
>  {
>      pulse_lock,
>      pulse_unlock,
> -    pulse_cond_wait,
>      pulse_main_loop,
>      pulse_create_stream,
>      pulse_release_stream,
> diff --git a/dlls/winepulse.drv/unixlib.h b/dlls/winepulse.drv/unixlib.h
> index 13793c734cd..797ed3bdaa5 100644
> --- a/dlls/winepulse.drv/unixlib.h
> +++ b/dlls/winepulse.drv/unixlib.h
> @@ -35,8 +35,7 @@ struct unix_funcs
>  {
>      void (WINAPI *lock)(void);
>      void (WINAPI *unlock)(void);
> -    int (WINAPI *cond_wait)(void);
> -    void (WINAPI *main_loop)(void);
> +    void (WINAPI *main_loop)(HANDLE event);
>      HRESULT (WINAPI *create_stream)(const char *name, EDataFlow dataflow, AUDCLNT_SHAREMODE mode,
>                                      DWORD flags, REFERENCE_TIME duration, REFERENCE_TIME period,
>                                      const WAVEFORMATEX *fmt, UINT32 *channel_count,
> 




More information about the wine-devel mailing list