// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Platform/CriticalSection.h"
///
/// Checks if current execution in on the main thread.
///
FLAXENGINE_API bool IsInMainThread();
///
/// 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 lock.
ScopeLock(const CriticalSection& section)
: _section(§ion)
{
_section->Lock();
}
///
/// Destructor, releases critical section.
///
~ScopeLock()
{
_section->Unlock();
}
};