mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Delete rtc::Thread::Dispose as unused
Bug: webrtc:8324 Change-Id: I18ed725bd95f133f4c43f1268eb37179053557da Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273104 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Auto-Submit: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37918}
This commit is contained in:
parent
4680f3370d
commit
71cf2d0eb1
3 changed files with 1 additions and 83 deletions
|
@ -29,7 +29,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include "absl/base/attributes.h"
|
#include "absl/base/attributes.h"
|
||||||
#include "absl/functional/any_invocable.h"
|
#include "absl/functional/any_invocable.h"
|
||||||
#include "absl/memory/memory.h"
|
|
||||||
#include "api/function_view.h"
|
#include "api/function_view.h"
|
||||||
#include "api/task_queue/task_queue_base.h"
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "api/units/time_delta.h"
|
#include "api/units/time_delta.h"
|
||||||
|
@ -298,14 +297,6 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
||||||
return messages_.size() + delayed_messages_.size();
|
return messages_.size() + delayed_messages_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internally posts a message which causes the doomed object to be deleted
|
|
||||||
// TODO(bugs.webrtc.org/8324): Delete when unused by dependencies.
|
|
||||||
template <class T>
|
|
||||||
void Dispose(T* doomed) {
|
|
||||||
RTC_DCHECK(doomed);
|
|
||||||
PostTask([dommed = absl::WrapUnique(doomed)] {});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsCurrent() const;
|
bool IsCurrent() const;
|
||||||
|
|
||||||
// Sleeps the calling thread for the specified number of milliseconds, during
|
// Sleeps the calling thread for the specified number of milliseconds, during
|
||||||
|
@ -509,8 +500,6 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
||||||
|
|
||||||
friend class ScopedDisallowBlockingCalls;
|
friend class ScopedDisallowBlockingCalls;
|
||||||
|
|
||||||
RecursiveCriticalSection* CritForTest() { return &crit_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int kSlowDispatchLoggingThreshold = 50; // 50 ms
|
static const int kSlowDispatchLoggingThreshold = 50; // 50 ms
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,6 @@ class DisposeData : public MessageData {
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t MQID_ANY = static_cast<uint32_t>(-1);
|
const uint32_t MQID_ANY = static_cast<uint32_t>(-1);
|
||||||
// TODO(bugs.webrtc.org/8324): Delete when unused by dependencies.
|
|
||||||
const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2);
|
|
||||||
|
|
||||||
// No destructor
|
// No destructor
|
||||||
|
|
||||||
|
|
|
@ -555,42 +555,6 @@ TEST(ThreadTest, ThreeThreadsInvoke) {
|
||||||
EXPECT_TRUE_WAIT(thread_a_called.Get(), 2000);
|
EXPECT_TRUE_WAIT(thread_a_called.Get(), 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThreadQueueTest : public ::testing::Test, public Thread {
|
|
||||||
public:
|
|
||||||
ThreadQueueTest() : Thread(CreateDefaultSocketServer(), true) {
|
|
||||||
RTC_DCHECK(Thread::Current() == nullptr);
|
|
||||||
ThreadManager::Instance()->SetCurrentThread(this);
|
|
||||||
}
|
|
||||||
~ThreadQueueTest() { ThreadManager::Instance()->SetCurrentThread(nullptr); }
|
|
||||||
bool IsLocked_Worker() {
|
|
||||||
if (!CritForTest()->TryEnter()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
CritForTest()->Leave();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool IsLocked() {
|
|
||||||
// We have to do this on a worker thread, or else the TryEnter will
|
|
||||||
// succeed, since our critical sections are reentrant.
|
|
||||||
std::unique_ptr<Thread> worker(Thread::CreateWithSocketServer());
|
|
||||||
worker->Start();
|
|
||||||
return worker->Invoke<bool>(RTC_FROM_HERE,
|
|
||||||
[this] { return IsLocked_Worker(); });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeletedLockChecker {
|
|
||||||
DeletedLockChecker(ThreadQueueTest* test, bool* was_locked, bool* deleted)
|
|
||||||
: test(test), was_locked(was_locked), deleted(deleted) {}
|
|
||||||
~DeletedLockChecker() {
|
|
||||||
*deleted = true;
|
|
||||||
*was_locked = test->IsLocked();
|
|
||||||
}
|
|
||||||
ThreadQueueTest* test;
|
|
||||||
bool* was_locked;
|
|
||||||
bool* deleted;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder(
|
static void DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder(
|
||||||
FakeClock& clock,
|
FakeClock& clock,
|
||||||
Thread& q) {
|
Thread& q) {
|
||||||
|
@ -614,7 +578,7 @@ static void DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder(
|
||||||
EXPECT_THAT(run_order, ElementsAre(0, 1, 2, 3, 4));
|
EXPECT_THAT(run_order, ElementsAre(0, 1, 2, 3, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ThreadQueueTest, DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder) {
|
TEST(ThreadTest, DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder) {
|
||||||
ScopedBaseFakeClock clock;
|
ScopedBaseFakeClock clock;
|
||||||
Thread q(CreateDefaultSocketServer(), true);
|
Thread q(CreateDefaultSocketServer(), true);
|
||||||
q.Start();
|
q.Start();
|
||||||
|
@ -626,39 +590,6 @@ TEST_F(ThreadQueueTest, DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder) {
|
||||||
DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder(clock, q_nullss);
|
DelayedPostsWithIdenticalTimesAreProcessedInFifoOrder(clock, q_nullss);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ThreadQueueTest, DisposeNotLocked) {
|
|
||||||
bool was_locked = true;
|
|
||||||
bool deleted = false;
|
|
||||||
DeletedLockChecker* d = new DeletedLockChecker(this, &was_locked, &deleted);
|
|
||||||
Dispose(d);
|
|
||||||
Message msg;
|
|
||||||
ProcessMessages(0);
|
|
||||||
EXPECT_TRUE(deleted);
|
|
||||||
EXPECT_FALSE(was_locked);
|
|
||||||
}
|
|
||||||
|
|
||||||
class DeletedMessageHandler : public MessageHandlerAutoCleanup {
|
|
||||||
public:
|
|
||||||
explicit DeletedMessageHandler(bool* deleted) : deleted_(deleted) {}
|
|
||||||
~DeletedMessageHandler() override { *deleted_ = true; }
|
|
||||||
void OnMessage(Message* msg) override {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool* deleted_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(ThreadQueueTest, DisposeHandlerWithPostedMessagePending) {
|
|
||||||
bool deleted = false;
|
|
||||||
DeletedMessageHandler* handler = new DeletedMessageHandler(&deleted);
|
|
||||||
// First, post a dispose.
|
|
||||||
Dispose(handler);
|
|
||||||
// Now, post a message, which should *not* be returned by Get().
|
|
||||||
Post(RTC_FROM_HERE, handler, 1);
|
|
||||||
Message msg;
|
|
||||||
ProcessMessages(0);
|
|
||||||
EXPECT_TRUE(deleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that ProcessAllMessageQueues does its essential function; process
|
// Ensure that ProcessAllMessageQueues does its essential function; process
|
||||||
// all messages (both delayed and non delayed) up until the current time, on
|
// all messages (both delayed and non delayed) up until the current time, on
|
||||||
// all registered message queues.
|
// all registered message queues.
|
||||||
|
|
Loading…
Reference in a new issue