Loading...
Searching...
No Matches
juce_CriticalSection.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API CriticalSection
{
public:
//==============================================================================
CriticalSection() noexcept;
~CriticalSection() noexcept;
//==============================================================================
void enter() const noexcept;
bool tryEnter() const noexcept;
void exit() const noexcept;
//==============================================================================
using ScopedLockType = GenericScopedLock<CriticalSection>;
using ScopedUnlockType = GenericScopedUnlock<CriticalSection>;
using ScopedTryLockType = GenericScopedTryLock<CriticalSection>;
private:
//==============================================================================
#if JUCE_WINDOWS
// To avoid including windows.h in the public JUCE headers, we'll just allocate
// a block of memory here that's big enough to be used internally as a windows
// CRITICAL_SECTION structure.
#if JUCE_64BIT
std::aligned_storage_t<44, 8> lock;
#else
std::aligned_storage_t<24, 8> lock;
#endif
#else
mutable pthread_mutex_t lock;
#endif
JUCE_DECLARE_NON_COPYABLE (CriticalSection)
};
//==============================================================================
class JUCE_API DummyCriticalSection
{
public:
inline DummyCriticalSection() = default;
inline ~DummyCriticalSection() = default;
inline void enter() const noexcept {}
inline bool tryEnter() const noexcept { return true; }
inline void exit() const noexcept {}
//==============================================================================
struct ScopedLockType
{
ScopedLockType (const DummyCriticalSection&) noexcept {}
};
using ScopedUnlockType = ScopedLockType;
private:
JUCE_DECLARE_NON_COPYABLE (DummyCriticalSection)
};
//==============================================================================
using ScopedLock = CriticalSection::ScopedLockType;
//==============================================================================
using ScopedUnlock = CriticalSection::ScopedUnlockType;
//==============================================================================
using ScopedTryLock = CriticalSection::ScopedTryLockType;
} // namespace juce
juce::CriticalSection::tryEnter
bool tryEnter() const noexcept
juce::CriticalSection::ScopedLockType
GenericScopedLock< CriticalSection > ScopedLockType
Definition juce_CriticalSection.h:93
juce::CriticalSection::ScopedUnlockType
GenericScopedUnlock< CriticalSection > ScopedUnlockType
Definition juce_CriticalSection.h:96
juce::CriticalSection::CriticalSection
CriticalSection() noexcept
juce::CriticalSection::ScopedTryLockType
GenericScopedTryLock< CriticalSection > ScopedTryLockType
Definition juce_CriticalSection.h:99
juce::CriticalSection::enter
void enter() const noexcept
juce::CriticalSection::exit
void exit() const noexcept
juce::DummyCriticalSection::ScopedUnlockType
ScopedLockType ScopedUnlockType
Definition juce_CriticalSection.h:151
juce::GenericScopedLock
Definition juce_ScopedLock.h:55
juce::GenericScopedTryLock
Definition juce_ScopedLock.h:198
juce::GenericScopedUnlock
Definition juce_ScopedLock.h:126
juce::DummyCriticalSection::ScopedLockType
Definition juce_CriticalSection.h:146