#include "rtc_base/thread.h"
#include "absl/strings/string_view.h"
#include "api/task_queue/task_queue_base.h"
#include "api/units/time_delta.h"
#include "rtc_base/socket_server.h"
#if defined(WEBRTC_WIN)
#include <comdef.h>
#elif defined(WEBRTC_POSIX)
#include <time.h>
#else
#error "Either WEBRTC_WIN or WEBRTC_POSIX needs to be defined."
#endif
#if defined(WEBRTC_WIN)
#pragma warning(disable : 4722)
#endif
#include <stdio.h>
#include <utility>
#include "absl/algorithm/container.h"
#include "absl/cleanup/cleanup.h"
#include "api/sequence_checker.h"
#include "rtc_base/checks.h"
#include "rtc_base/event.h"
#include "rtc_base/internal/default_socket_server.h"
#include "rtc_base/logging.h"
#include "rtc_base/null_socket_server.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
#if defined(WEBRTC_MAC)
#include "rtc_base/system/cocoa_threading.h"
extern "C" {
void* objc_autoreleasePoolPush(void);
void objc_autoreleasePoolPop(void* pool);
}
namespace {
class ScopedAutoReleasePool {
public:
ScopedAutoReleasePool() : pool_(objc_autoreleasePoolPush()) {}
~ScopedAutoReleasePool() { objc_autoreleasePoolPop(pool_); }
private:
void* const pool_;
};
}
#endif
namespace rtc {
MutexLock;
TimeDelta;
ThreadManager* ThreadManager::Instance() { … }
ThreadManager::~ThreadManager() { … }
void ThreadManager::Add(Thread* message_queue) { … }
void ThreadManager::AddInternal(Thread* message_queue) { … }
void ThreadManager::Remove(Thread* message_queue) { … }
void ThreadManager::RemoveInternal(Thread* message_queue) { … }
#if RTC_DCHECK_IS_ON
void ThreadManager::RemoveFromSendGraph(Thread* thread) { … }
void ThreadManager::RegisterSendAndCheckForCycles(Thread* source,
Thread* target) { … }
#endif
void ThreadManager::ProcessAllMessageQueuesForTesting() { … }
void ThreadManager::ProcessAllMessageQueuesInternal() { … }
Thread* Thread::Current() { … }
#if defined(WEBRTC_POSIX)
ThreadManager::ThreadManager() { … }
Thread* ThreadManager::CurrentThread() { … }
void ThreadManager::SetCurrentThreadInternal(Thread* thread) { … }
#endif
#if defined(WEBRTC_WIN)
ThreadManager::ThreadManager() : key_(TlsAlloc()) {}
Thread* ThreadManager::CurrentThread() {
return static_cast<Thread*>(TlsGetValue(key_));
}
void ThreadManager::SetCurrentThreadInternal(Thread* thread) {
TlsSetValue(key_, thread);
}
#endif
void ThreadManager::SetCurrentThread(Thread* thread) { … }
void rtc::ThreadManager::ChangeCurrentThreadForTest(rtc::Thread* thread) { … }
Thread* ThreadManager::WrapCurrentThread() { … }
void ThreadManager::UnwrapCurrentThread() { … }
Thread::ScopedDisallowBlockingCalls::ScopedDisallowBlockingCalls()
: … { … }
Thread::ScopedDisallowBlockingCalls::~ScopedDisallowBlockingCalls() { … }
#if RTC_DCHECK_IS_ON
Thread::ScopedCountBlockingCalls::ScopedCountBlockingCalls(
std::function<void(uint32_t, uint32_t)> callback)
: … { … }
Thread::ScopedCountBlockingCalls::~ScopedCountBlockingCalls() { … }
uint32_t Thread::ScopedCountBlockingCalls::GetBlockingCallCount() const { … }
uint32_t Thread::ScopedCountBlockingCalls::GetCouldBeBlockingCallCount() const { … }
uint32_t Thread::ScopedCountBlockingCalls::GetTotalBlockedCallCount() const { … }
#endif
Thread::Thread(SocketServer* ss) : … { … }
Thread::Thread(std::unique_ptr<SocketServer> ss)
: … { … }
Thread::Thread(SocketServer* ss, bool do_init)
: … { … }
Thread::Thread(std::unique_ptr<SocketServer> ss, bool do_init)
: … { … }
Thread::~Thread() { … }
void Thread::DoInit() { … }
void Thread::DoDestroy() { … }
SocketServer* Thread::socketserver() { … }
void Thread::WakeUpSocketServer() { … }
void Thread::Quit() { … }
bool Thread::IsQuitting() { … }
void Thread::Restart() { … }
absl::AnyInvocable<void() &&> Thread::Get(int cmsWait) { … }
void Thread::PostTaskImpl(absl::AnyInvocable<void() &&> task,
const PostTaskTraits& traits,
const webrtc::Location& location) { … }
void Thread::PostDelayedTaskImpl(absl::AnyInvocable<void() &&> task,
webrtc::TimeDelta delay,
const PostDelayedTaskTraits& traits,
const webrtc::Location& location) { … }
int Thread::GetDelay() { … }
void Thread::Dispatch(absl::AnyInvocable<void() &&> task) { … }
bool Thread::IsCurrent() const { … }
std::unique_ptr<Thread> Thread::CreateWithSocketServer() { … }
std::unique_ptr<Thread> Thread::Create() { … }
bool Thread::SleepMs(int milliseconds) { … }
bool Thread::SetName(absl::string_view name, const void* obj) { … }
void Thread::SetDispatchWarningMs(int deadline) { … }
bool Thread::Start() { … }
bool Thread::WrapCurrent() { … }
void Thread::UnwrapCurrent() { … }
void Thread::SafeWrapCurrent() { … }
void Thread::Join() { … }
bool Thread::SetAllowBlockingCalls(bool allow) { … }
void Thread::AssertBlockingIsAllowedOnCurrentThread() { … }
#if defined(WEBRTC_WIN)
DWORD WINAPI Thread::PreRun(LPVOID pv) {
#else
void* Thread::PreRun(void* pv) { … }
void Thread::Run() { … }
bool Thread::IsOwned() { … }
void Thread::Stop() { … }
void Thread::BlockingCallImpl(rtc::FunctionView<void()> functor,
const webrtc::Location& location) { … }
void Thread::EnsureIsCurrentTaskQueue() { … }
void Thread::ClearCurrentTaskQueue() { … }
void Thread::AllowInvokesToThread(Thread* thread) { … }
void Thread::DisallowAllInvokes() { … }
#if RTC_DCHECK_IS_ON
uint32_t Thread::GetBlockingCallCount() const { … }
uint32_t Thread::GetCouldBeBlockingCallCount() const { … }
#endif
bool Thread::IsInvokeToThreadAllowed(rtc::Thread* target) { … }
void Thread::Delete() { … }
bool Thread::IsProcessingMessagesForTesting() { … }
bool Thread::ProcessMessages(int cmsLoop) { … }
bool Thread::WrapCurrentWithThreadManager(ThreadManager* thread_manager,
bool need_synchronize_access) { … }
bool Thread::IsRunning() { … }
AutoThread::AutoThread()
: … { … }
AutoThread::~AutoThread() { … }
AutoSocketServerThread::AutoSocketServerThread(SocketServer* ss)
: … { … }
AutoSocketServerThread::~AutoSocketServerThread() { … }
}