Change ObjCNetworkMonitor::OnPathUpdate to use PostTask
Removes use of AsyncInvoker, replaced with PendingTaskSafetyFlag. The latter is extended to support creation on a different thread than where it will be used, and to support stop and restart. Bug: webrtc:12339 Change-Id: I28b6e09b1542f50037e842ef5fe3a47d15704b46 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211002 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33432}
This commit is contained in:
@ -24,6 +24,11 @@ void PendingTaskSafetyFlag::SetNotAlive() {
|
||||
alive_ = false;
|
||||
}
|
||||
|
||||
void PendingTaskSafetyFlag::SetAlive() {
|
||||
RTC_DCHECK_RUN_ON(&main_sequence_);
|
||||
alive_ = true;
|
||||
}
|
||||
|
||||
bool PendingTaskSafetyFlag::alive() const {
|
||||
RTC_DCHECK_RUN_ON(&main_sequence_);
|
||||
return alive_;
|
||||
|
@ -62,6 +62,7 @@ class PendingTaskSafetyFlag : public rtc::RefCountInterface {
|
||||
~PendingTaskSafetyFlag() = default;
|
||||
|
||||
void SetNotAlive();
|
||||
void SetAlive();
|
||||
bool alive() const;
|
||||
|
||||
protected:
|
||||
|
@ -1560,6 +1560,8 @@ if (is_ios || is_mac) {
|
||||
"../api:sequence_checker",
|
||||
"../rtc_base",
|
||||
"../rtc_base:threading",
|
||||
"../rtc_base/task_utils:pending_task_safety_flag",
|
||||
"../rtc_base/task_utils:to_queued_task",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "api/sequence_checker.h"
|
||||
#include "rtc_base/async_invoker.h"
|
||||
#include "rtc_base/network_monitor.h"
|
||||
#include "rtc_base/network_monitor_factory.h"
|
||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "sdk/objc/components/network/RTCNetworkMonitor+Private.h"
|
||||
@ -35,7 +35,7 @@ class ObjCNetworkMonitorFactory : public rtc::NetworkMonitorFactory {
|
||||
class ObjCNetworkMonitor : public rtc::NetworkMonitorInterface,
|
||||
public NetworkMonitorObserver {
|
||||
public:
|
||||
ObjCNetworkMonitor() = default;
|
||||
ObjCNetworkMonitor();
|
||||
~ObjCNetworkMonitor() override;
|
||||
|
||||
void Start() override;
|
||||
@ -58,7 +58,7 @@ class ObjCNetworkMonitor : public rtc::NetworkMonitorInterface,
|
||||
bool started_ = false;
|
||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name_
|
||||
RTC_GUARDED_BY(thread_);
|
||||
rtc::AsyncInvoker invoker_;
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_;
|
||||
RTCNetworkMonitor* network_monitor_ = nil;
|
||||
};
|
||||
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "sdk/objc/native/src/objc_network_monitor.h"
|
||||
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "rtc_base/logging.h"
|
||||
@ -20,6 +22,10 @@ rtc::NetworkMonitorInterface* ObjCNetworkMonitorFactory::CreateNetworkMonitor()
|
||||
return new ObjCNetworkMonitor();
|
||||
}
|
||||
|
||||
ObjCNetworkMonitor::ObjCNetworkMonitor() {
|
||||
safety_flag_ = PendingTaskSafetyFlag::Create();
|
||||
}
|
||||
|
||||
ObjCNetworkMonitor::~ObjCNetworkMonitor() {
|
||||
network_monitor_ = nil;
|
||||
}
|
||||
@ -30,6 +36,7 @@ void ObjCNetworkMonitor::Start() {
|
||||
}
|
||||
thread_ = rtc::Thread::Current();
|
||||
RTC_DCHECK_RUN_ON(thread_);
|
||||
safety_flag_->SetAlive();
|
||||
network_monitor_ = [[RTCNetworkMonitor alloc] initWithObserver:this];
|
||||
if (network_monitor_ == nil) {
|
||||
RTC_LOG(LS_WARNING) << "Failed to create RTCNetworkMonitor; not available on this OS?";
|
||||
@ -42,6 +49,7 @@ void ObjCNetworkMonitor::Stop() {
|
||||
if (!started_) {
|
||||
return;
|
||||
}
|
||||
safety_flag_->SetNotAlive();
|
||||
network_monitor_ = nil;
|
||||
started_ = false;
|
||||
}
|
||||
@ -76,11 +84,11 @@ bool ObjCNetworkMonitor::IsAdapterAvailable(const std::string& interface_name) {
|
||||
void ObjCNetworkMonitor::OnPathUpdate(
|
||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name) {
|
||||
RTC_DCHECK(network_monitor_ != nil);
|
||||
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, thread_, [this, adapter_type_by_name] {
|
||||
thread_->PostTask(ToQueuedTask(safety_flag_, [this, adapter_type_by_name] {
|
||||
RTC_DCHECK_RUN_ON(thread_);
|
||||
adapter_type_by_name_ = adapter_type_by_name;
|
||||
SignalNetworksChanged();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
Reference in New Issue
Block a user