chromium/third_party/webrtc/rtc_base/thread.cc

/*
 *  Copyright 2004 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 "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)
// Disable warning that we don't care about:
// warning C4722: destructor never returns, potential memory leak
#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"

/*
 * These are forward-declarations for methods that are part of the
 * ObjC runtime. They are declared in the private header objc-internal.h.
 * These calls are what clang inserts when using @autoreleasepool in ObjC,
 * but here they are used directly in order to keep this file C++.
 * https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support
 */
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_;
};
}  // namespace
#endif

namespace rtc {

MutexLock;
TimeDelta;

ThreadManager* ThreadManager::Instance() {}

ThreadManager::~ThreadManager() {}

// static
void ThreadManager::Add(Thread* message_queue) {}
void ThreadManager::AddInternal(Thread* message_queue) {}

// static
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

// static
void ThreadManager::ProcessAllMessageQueuesForTesting() {}

void ThreadManager::ProcessAllMessageQueuesInternal() {}

// static
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) {}

// static
void Thread::AssertBlockingIsAllowedOnCurrentThread() {}

// static
#if defined(WEBRTC_WIN)
DWORD WINAPI Thread::PreRun(LPVOID pv) {
#else
void* Thread::PreRun(void* pv) {}  // namespace rtc

void Thread::Run() {}

bool Thread::IsOwned() {}

void Thread::Stop() {}

void Thread::BlockingCallImpl(rtc::FunctionView<void()> functor,
                              const webrtc::Location& location) {}

// Called by the ThreadManager when being set as the current thread.
void Thread::EnsureIsCurrentTaskQueue() {}

// Called by the ThreadManager when being set as the current thread.
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

// Returns true if no policies added or if there is at least one policy
// that permits invocation to `target` thread.
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() {}

}  // namespace rtc