Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1185)

Unified Diff: webrtc/rtc_base/task_queue_impl_factory.cc

Issue 2936213003: Test using a global, replacable TaskQueueImpl factory.
Patch Set: Added global factory. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/rtc_base/task_queue_impl_factory.cc
diff --git a/webrtc/rtc_base/task_queue_impl_factory.cc b/webrtc/rtc_base/task_queue_impl_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..433da0cb6d3603e787879bc7aeb074babe6a167a
--- /dev/null
+++ b/webrtc/rtc_base/task_queue_impl_factory.cc
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <webrtc/rtc_base/task_queue_impl_factory.h>
+
+namespace rtc {
+
+// TODO(perkj): now!! Do we have a way to lazy instantiate ? OnceInit...
+static TaskQueueImplFactory* taskqueue_factory = nullptr;
+static rtc::CriticalSection set_lock;
+
+// Sets the factory to be used by this process. May only be called once
+// before any TaskQueues are created.
+// static
+void TaskQueueImplFactory::Set(TaskQueueImplFactory* factory) {
kwiberg-webrtc 2017/08/21 09:21:55 Is it really a good idea for Set() to not take own
+ rtc::CritScope lock(&set_lock);
+ // TODO(perkj): if OnceInit exist... DOn't allow someone to call Set again.
nisse-webrtc 2017/08/18 11:45:45 If you can put a static variable in a single metho
+ if (taskqueue_factory)
+ return;
kwiberg-webrtc 2017/08/21 09:21:55 If the contract is that you're only allowed to cal
+ taskqueue_factory = factory;
+}
+
+TaskQueueImplFactory* TaskQueueImplFactory::Get() {
+ if (taskqueue_factory)
kwiberg-webrtc 2017/08/21 09:21:55 Don't read this variable without taking the lock.
+ return taskqueue_factory;
+#if defined(WEBRTC_LINUX)
+ Set(new TaskQueueLibEventFactory());
+#endif
+ return taskqueue_factory;
+}
+
+} // namespace rtc

Powered by Google App Engine
This is Rietveld 408576698