@@ -147,20 +147,6 @@ struct auto_lock {
147147 owned_critical_section * lock;
148148};
149149
150- struct auto_unlock {
151- auto_unlock (owned_critical_section * lock)
152- : lock(lock)
153- {
154- lock->leave ();
155- }
156- ~auto_unlock ()
157- {
158- lock->enter ();
159- }
160- private:
161- owned_critical_section * lock;
162- };
163-
164150struct auto_com {
165151 auto_com () {
166152 result = CoInitializeEx (NULL , COINIT_MULTITHREADED);
@@ -984,7 +970,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
984970 hr = get_default_endpoint (&device);
985971 if (FAILED (hr)) {
986972 LOG (" Could not get default endpoint, error: %x\n " , hr);
987- auto_unlock unlock ( stm->stream_reset_lock );
973+ stm->stream_reset_lock -> leave ( );
988974 wasapi_stream_destroy (stm);
989975 return CUBEB_ERROR;
990976 }
@@ -997,7 +983,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
997983 SafeRelease (device);
998984 if (FAILED (hr)) {
999985 LOG (" Could not activate the device to get an audio client: error: %x\n " , hr);
1000- auto_unlock unlock ( stm->stream_reset_lock );
986+ stm->stream_reset_lock -> leave ( );
1001987 wasapi_stream_destroy (stm);
1002988 return CUBEB_ERROR;
1003989 }
@@ -1007,7 +993,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
1007993 hr = stm->client ->GetMixFormat (&mix_format);
1008994 if (FAILED (hr)) {
1009995 LOG (" Could not fetch current mix format from the audio client: error: %x\n " , hr);
1010- auto_unlock unlock ( stm->stream_reset_lock );
996+ stm->stream_reset_lock -> leave ( );
1011997 wasapi_stream_destroy (stm);
1012998 return CUBEB_ERROR;
1013999 }
@@ -1032,15 +1018,15 @@ int setup_wasapi_stream(cubeb_stream * stm)
10321018
10331019 if (FAILED (hr)) {
10341020 LOG (" Unable to initialize audio client: %x.\n " , hr);
1035- auto_unlock unlock ( stm->stream_reset_lock );
1021+ stm->stream_reset_lock -> leave ( );
10361022 wasapi_stream_destroy (stm);
10371023 return CUBEB_ERROR;
10381024 }
10391025
10401026 hr = stm->client ->GetBufferSize (&stm->buffer_frame_count );
10411027 if (FAILED (hr)) {
10421028 LOG (" Could not get the buffer size from the client %x.\n " , hr);
1043- auto_unlock unlock ( stm->stream_reset_lock );
1029+ stm->stream_reset_lock -> leave ( );
10441030 wasapi_stream_destroy (stm);
10451031 return CUBEB_ERROR;
10461032 }
@@ -1052,7 +1038,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
10521038 hr = stm->client ->SetEventHandle (stm->refill_event );
10531039 if (FAILED (hr)) {
10541040 LOG (" Could set the event handle for the client %x.\n " , hr);
1055- auto_unlock unlock ( stm->stream_reset_lock );
1041+ stm->stream_reset_lock -> leave ( );
10561042 wasapi_stream_destroy (stm);
10571043 return CUBEB_ERROR;
10581044 }
@@ -1061,7 +1047,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
10611047 (void **)&stm->render_client );
10621048 if (FAILED (hr)) {
10631049 LOG (" Could not get the render client %x.\n " , hr);
1064- auto_unlock unlock ( stm->stream_reset_lock );
1050+ stm->stream_reset_lock -> leave ( );
10651051 wasapi_stream_destroy (stm);
10661052 return CUBEB_ERROR;
10671053 }
@@ -1070,7 +1056,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
10701056 (void **)&stm->audio_stream_volume );
10711057 if (FAILED (hr)) {
10721058 LOG (" Could not get the IAudioStreamVolume %x.\n " , hr);
1073- auto_unlock unlock ( stm->stream_reset_lock );
1059+ stm->stream_reset_lock -> leave ( );
10741060 wasapi_stream_destroy (stm);
10751061 return CUBEB_ERROR;
10761062 }
@@ -1087,7 +1073,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
10871073 CUBEB_RESAMPLER_QUALITY_DESKTOP);
10881074 if (!stm->resampler ) {
10891075 LOG (" Could not get a resampler\n " );
1090- auto_unlock unlock ( stm->stream_reset_lock );
1076+ stm->stream_reset_lock -> leave ( );
10911077 wasapi_stream_destroy (stm);
10921078 return CUBEB_ERROR;
10931079 }
@@ -1249,8 +1235,9 @@ int stream_stop(cubeb_stream * stm, bool * was_running)
12491235 }
12501236
12511237 {
1252- auto_unlock lock ( stm->stream_reset_lock );
1238+ stm->stream_reset_lock -> leave ( );
12531239 stop_and_join_render_thread (stm);
1240+ stm->stream_reset_lock ->enter ();
12541241 }
12551242
12561243 if (SUCCEEDED (hr)) {
0 commit comments