Skip to content

Commit

Permalink
Bug 1133190 - Don't use auto_unlock in paths where lock is being dest…
Browse files Browse the repository at this point in the history
…royed. r=kinetik
  • Loading branch information
padenot committed Feb 19, 2015
1 parent c349176 commit 67200dd
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions media/libcubeb/src/cubeb_wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,6 @@ struct auto_lock {
owned_critical_section * lock;
};

struct auto_unlock {
auto_unlock(owned_critical_section * lock)
: lock(lock)
{
lock->leave();
}
~auto_unlock()
{
lock->enter();
}
private:
owned_critical_section * lock;
};

struct auto_com {
auto_com() {
result = CoInitializeEx(NULL, COINIT_MULTITHREADED);
Expand Down Expand Up @@ -984,7 +970,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
hr = get_default_endpoint(&device);
if (FAILED(hr)) {
LOG("Could not get default endpoint, error: %x\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -997,7 +983,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
SafeRelease(device);
if (FAILED(hr)) {
LOG("Could not activate the device to get an audio client: error: %x\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -1007,7 +993,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
hr = stm->client->GetMixFormat(&mix_format);
if (FAILED(hr)) {
LOG("Could not fetch current mix format from the audio client: error: %x\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -1032,15 +1018,15 @@ int setup_wasapi_stream(cubeb_stream * stm)

if (FAILED(hr)) {
LOG("Unable to initialize audio client: %x.\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}

hr = stm->client->GetBufferSize(&stm->buffer_frame_count);
if (FAILED(hr)) {
LOG("Could not get the buffer size from the client %x.\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -1052,7 +1038,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
hr = stm->client->SetEventHandle(stm->refill_event);
if (FAILED(hr)) {
LOG("Could set the event handle for the client %x.\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -1061,7 +1047,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
(void **)&stm->render_client);
if (FAILED(hr)) {
LOG("Could not get the render client %x.\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -1070,7 +1056,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
(void **)&stm->audio_stream_volume);
if (FAILED(hr)) {
LOG("Could not get the IAudioStreamVolume %x.\n", hr);
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand All @@ -1087,7 +1073,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
CUBEB_RESAMPLER_QUALITY_DESKTOP);
if (!stm->resampler) {
LOG("Could not get a resampler\n");
auto_unlock unlock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}
Expand Down Expand Up @@ -1249,8 +1235,9 @@ int stream_stop(cubeb_stream * stm, bool * was_running)
}

{
auto_unlock lock(stm->stream_reset_lock);
stm->stream_reset_lock->leave();
stop_and_join_render_thread(stm);
stm->stream_reset_lock->enter();
}

if (SUCCEEDED(hr)) {
Expand Down

0 comments on commit 67200dd

Please sign in to comment.