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

Unified Diff: webrtc/base/nethelpers.cc

Issue 2915253002: Delete SignalThread class. (Closed)
Patch Set: Write the member variables for the result only on the |construction_thread_|. Created 3 years, 6 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/base/nethelpers.cc
diff --git a/webrtc/base/nethelpers.cc b/webrtc/base/nethelpers.cc
index 6c11ef8c38fa04800df834bc8fa0f0f8939b3b89..037df428dbe44d183cd6c039fd6c128fad49618b 100644
--- a/webrtc/base/nethelpers.cc
+++ b/webrtc/base/nethelpers.cc
@@ -25,13 +25,15 @@
#endif
#endif // defined(WEBRTC_POSIX) && !defined(__native_client__)
+#include "webrtc/base/bind.h"
#include "webrtc/base/byteorder.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
-#include "webrtc/base/signalthread.h"
+#include "webrtc/base/thread.h"
namespace rtc {
+namespace {
int ResolveHostname(const std::string& hostname, int family,
std::vector<IPAddress>* addresses) {
#ifdef __native_client__
@@ -81,17 +83,23 @@ int ResolveHostname(const std::string& hostname, int family,
return 0;
#endif // !__native_client__
}
+} // namespace
// AsyncResolver
AsyncResolver::AsyncResolver()
- : SignalThread(false /* use_socket_server */), error_(-1) {}
+ : construction_thread_(Thread::Current()),
+ worker_(&ThreadEntry_w, this, "AsyncResolver") {}
-AsyncResolver::~AsyncResolver() = default;
+AsyncResolver::~AsyncResolver() {
+ RTC_DCHECK(construction_thread_->IsCurrent());
+ worker_.Stop();
+}
void AsyncResolver::Start(const SocketAddress& addr) {
+ RTC_DCHECK(construction_thread_->IsCurrent());
+ RTC_DCHECK(!worker_.IsRunning());
addr_ = addr;
- // SignalThred Start will kickoff the resolve process.
- SignalThread::Start();
+ worker_.Start();
tommi 2017/06/15 10:20:32 implementing a custom QueuedTask that handles the
nisse-webrtc 2017/06/15 11:33:47 I'll give it a try.
}
bool AsyncResolver::GetResolvedAddress(int family, SocketAddress* addr) const {
@@ -113,18 +121,37 @@ int AsyncResolver::GetError() const {
}
void AsyncResolver::Destroy(bool wait) {
- SignalThread::Destroy(wait);
+ RTC_DCHECK(construction_thread_->IsCurrent());
+ // If we don't wait here, we will nevertheless wait in the destructor.
+ if (wait) {
tommi 2017/06/15 10:20:32 why is wait == false supported?
nisse-webrtc 2017/06/15 11:33:47 It's part of the AsyncResolverInterface, which I d
+ worker_.Stop();
+ }
}
-void AsyncResolver::DoWork() {
- error_ = ResolveHostname(addr_.hostname().c_str(), addr_.family(),
- &addresses_);
+void AsyncResolver::ResolveAddress_w() {
+ RTC_DCHECK(IsThreadRefEqual(worker_.GetThreadRef(), CurrentThreadRef()));
+ std::vector<IPAddress> addresses;
+ int error = ResolveHostname(addr_.hostname().c_str(), addr_.family(),
+ &addresses);
+ // Ensure SignalDone is called on the main thread.
+ construction_thread_->Invoke<void>(
nisse-webrtc 2017/06/09 09:44:52 Actually, I don't think there's any need for this
Taylor Brandstetter 2017/06/09 18:02:58 Using an AsyncInvoker is the most convenient way I
+ RTC_FROM_HERE, rtc::Bind(&AsyncResolver::ResolveDone, this,
+ error, addresses));
tommi 2017/06/15 10:20:32 std::move? (or will address be implicitly moved?)
nisse-webrtc 2017/06/15 11:33:47 Done.
}
-void AsyncResolver::OnWorkDone() {
+void AsyncResolver::ResolveDone(int error, std::vector<IPAddress> addresses) {
+ RTC_DCHECK(construction_thread_->IsCurrent());
+ error_ = error;
+ addresses_ = addresses;
tommi 2017/06/15 10:20:32 std::move
SignalDone(this);
}
+// static
+void AsyncResolver::ThreadEntry_w(void* p) {
tommi 2017/06/15 10:20:32 What about using a TaskQueue?
+ AsyncResolver* resolver = static_cast<AsyncResolver*>(p);
+ resolver->ResolveAddress_w();
+}
+
const char* inet_ntop(int af, const void *src, char* dst, socklen_t size) {
#if defined(WEBRTC_WIN)
return win32_inet_ntop(af, src, dst, size);

Powered by Google App Engine
This is Rietveld 408576698