#ifndef BASE_THREADING_SCOPED_THREAD_PRIORITY_H_
#define BASE_THREADING_SCOPED_THREAD_PRIORITY_H_
#include <atomic>
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace base {
class Location;
enum class ThreadType : int;
#define INTERNAL_SCOPED_THREAD_PRIORITY_CONCAT(a, b) a##b
#define INTERNAL_SCOPED_THREAD_PRIORITY_CONCAT1(a, b) \
INTERNAL_SCOPED_THREAD_PRIORITY_CONCAT(a, b)
#define INTERNAL_SCOPED_THREAD_PRIORITY_APPEND_LINE(name) \
INTERNAL_SCOPED_THREAD_PRIORITY_CONCAT1(name, __LINE__)
#define SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY() \
static std::atomic_bool INTERNAL_SCOPED_THREAD_PRIORITY_APPEND_LINE( \
already_loaded){false}; \
base::internal::ScopedMayLoadLibraryAtBackgroundPriority \
INTERNAL_SCOPED_THREAD_PRIORITY_APPEND_LINE( \
scoped_may_load_library_at_background_priority)( \
FROM_HERE, \
&INTERNAL_SCOPED_THREAD_PRIORITY_APPEND_LINE(already_loaded));
#define SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY_REPEATEDLY() \
base::internal::ScopedMayLoadLibraryAtBackgroundPriority \
INTERNAL_SCOPED_THREAD_PRIORITY_APPEND_LINE( \
scoped_may_load_library_at_background_priority)(FROM_HERE, nullptr);
class BASE_EXPORT ScopedBoostPriority {
public:
explicit ScopedBoostPriority(ThreadType target_thread_type);
~ScopedBoostPriority();
ScopedBoostPriority(const ScopedBoostPriority&) = delete;
ScopedBoostPriority& operator=(const ScopedBoostPriority&) = delete;
private:
absl::optional<ThreadType> original_thread_type_;
};
namespace internal {
class BASE_EXPORT ScopedMayLoadLibraryAtBackgroundPriority {
public:
explicit ScopedMayLoadLibraryAtBackgroundPriority(
const Location& from_here,
std::atomic_bool* already_loaded);
ScopedMayLoadLibraryAtBackgroundPriority(
const ScopedMayLoadLibraryAtBackgroundPriority&) = delete;
ScopedMayLoadLibraryAtBackgroundPriority& operator=(
const ScopedMayLoadLibraryAtBackgroundPriority&) = delete;
~ScopedMayLoadLibraryAtBackgroundPriority();
private:
#if BUILDFLAG(IS_WIN)
absl::optional<ThreadType> original_thread_type_;
const raw_ptr<std::atomic_bool> already_loaded_;
#endif
};
}
}
#endif