// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Platform/Platform.h" #include "Engine/Platform/CriticalSection.h" #include "Engine/Engine/Globals.h" /// /// Checks if current execution in on the main thread. /// /// True if running on the main thread, otherwise false. inline bool IsInMainThread() { return Globals::MainThreadID == Platform::GetCurrentThreadID(); } /// /// Scope locker for critical section. /// class ScopeLock { private: const CriticalSection* _section; ScopeLock() = default; ScopeLock(const ScopeLock&) = delete; ScopeLock& operator=(const ScopeLock&) = delete; public: /// /// Init, enters critical section /// /// The synchronization object to manage ScopeLock(const CriticalSection* section) : _section(section) { ASSERT_LOW_LAYER(_section); _section->Lock(); } /// /// Init, enters critical section /// /// The synchronization object to manage ScopeLock(const CriticalSection& section) : _section(§ion) { _section->Lock(); } /// /// Destructor, releases critical section /// ~ScopeLock() { _section->Unlock(); } };