Program Listing for File critical-section.h
↰ Return to documentation for file (include\concurrent\critical-section.h
)
/******************************************************************************
© Intel Corporation.
This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.
This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.
******************************************************************************/
#pragma once
#ifdef _WIN32
#include <Windows.h>
using SynchronizationPrimitive = CRITICAL_SECTION;
#else
#include <mutex>
using SynchronizationPrimitive = std::mutex;
#endif
#include <memory>
#include "instrumentation/gpa_itt_notify.h"
#ifndef INTEL_NO_ITTNOTIFY_API
namespace itt_notify {
class Overlapped;
}
#endif
namespace gpa {
namespace concurrent {
struct CriticalSection;
struct CriticalSectionScopedLock
{
CriticalSection& mCriticalSection;
bool mEntered = false;
CriticalSectionScopedLock(CriticalSection& criticalSection, bool dontEnter = false);
void Enter();
void Leave();
~CriticalSectionScopedLock();
};
struct CriticalSection
{
SynchronizationPrimitive mCriticalSectionPrimitive;
CriticalSection();
~CriticalSection();
void Enter();
void Leave();
CriticalSectionScopedLock ObtainScopedLock(bool dontEnter = false);
#if !defined(INTEL_NO_ITTNOTIFY_API) && !defined(__linux__)
std::unique_ptr<itt_notify::Overlapped> m_itt;
#endif
};
} // namespace concurrent
} // namespace gpa