Bug 1308423 - Don't copy owned_critical_section in cubeb. r?kinetik
MozReview-Commit-ID: 6Al3a6satCi
--- a/media/libcubeb/src/cubeb_audiounit.cpp
+++ b/media/libcubeb/src/cubeb_audiounit.cpp
@@ -438,17 +438,18 @@ audiounit_init(cubeb ** context, char co
*context = NULL;
ctx = new cubeb;
assert(ctx);
PodZero(ctx, 1);
ctx->ops = &audiounit_ops;
- ctx->mutex = owned_critical_section();
+ // Call ctor directly because a mutex cannot be copied.
+ ctx->mutex.owned_critical_section::owned_critical_section();
ctx->active_streams = 0;
ctx->limit_streams = kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7;
#if !TARGET_OS_IPHONE
cubeb_set_coreaudio_notification_runloop();
#endif
@@ -1139,17 +1140,18 @@ audiounit_stream_init(cubeb * context,
* full-duplex stream and different devices for input vs output. */
stm->input_unit = (input_stream_params != NULL) ? input_unit : NULL;
stm->output_unit = (output_stream_params != NULL) ? output_unit : NULL;
stm->context = context;
stm->data_callback = data_callback;
stm->state_callback = state_callback;
stm->user_ptr = user_ptr;
stm->device_changed_callback = NULL;
- stm->mutex = owned_critical_section();
+ // Call ctor directly because a mutex cannot be copied.
+ stm->mutex.owned_critical_section::owned_critical_section();
/* Init data members where necessary */
stm->hw_latency_frames = UINT64_MAX;
/* Silently clamp the latency down to the platform default, because we
* synthetize the clock from the callbacks, and we want the clock to update
* often. */
latency_frames = audiounit_clamp_latency(stm, latency_frames);
--- a/media/libcubeb/src/cubeb_utils_unix.h
+++ b/media/libcubeb/src/cubeb_utils_unix.h
@@ -75,11 +75,15 @@ public:
#ifdef DEBUG
int r = pthread_mutex_lock(&mutex);
assert(r == EDEADLK);
#endif
}
private:
pthread_mutex_t mutex;
+
+ // Disallow copy and assignment because pthread_mutex_t cannot be copied.
+ owned_critical_section(const owned_critical_section&);
+ owned_critical_section& operator=(const owned_critical_section&);
};
#endif /* CUBEB_UTILS_UNIX */
--- a/media/libcubeb/src/cubeb_utils_win.h
+++ b/media/libcubeb/src/cubeb_utils_win.h
@@ -57,11 +57,15 @@ public:
#endif
}
private:
CRITICAL_SECTION critical_section;
#ifdef DEBUG
DWORD owner;
#endif
+
+ // Disallow copy and assignment because CRICICAL_SECTION cannot be copied.
+ owned_critical_section(const owned_critical_section&);
+ owned_critical_section& operator=(const owned_critical_section&);
};
#endif /* CUBEB_UTILS_WIN */
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -1637,17 +1637,18 @@ wasapi_stream_init(cubeb * context, cube
if (output_stream_params) {
stm->output_stream_params = *output_stream_params;
stm->output_device = output_device;
}
stm->latency = latency_frames;
stm->volume = 1.0;
- stm->stream_reset_lock = owned_critical_section();
+ // Call ctor directly because a critical section cannot be copied.
+ stm->stream_reset_lock.owned_critical_section::owned_critical_section();
stm->reconfigure_event = CreateEvent(NULL, 0, 0, NULL);
if (!stm->reconfigure_event) {
LOG("Can't create the reconfigure event, error: %x\n", GetLastError());
wasapi_stream_destroy(stm);
return CUBEB_ERROR;
}