Proud::CriticalSection Class Reference

Public Member Functions

PROUD_API CriticalSection ()
 
PROUD_API CriticalSection (CriticalSectionSettings &settings)
 
PROUD_API ~CriticalSection (void)
 
PROUD_API void Lock ()
 
PROUD_API void UnsafeLock ()
 
PROUD_API void Unlock ()
 
PROUD_API bool TryLock ()
 
PROUD_API bool IsValid ()
 
bool IsLockedByCurrentThread () const
 
bool IsLocked () const
 
void Reset (CriticalSectionSettings &settings)
 
void ShowErrorOnInvalidState ()
 
uint64_t GetLastLockedThreadID ()
 

Public Attributes

bool m_neverCallDtor
 
int m_tryLockSuccessCount
 
int m_tryLockFailCount
 

Detailed Description

Critical section (class)

  • More fortified features than CCriticalSection of MFC environment
  • A spin lock is set as default in order to minimize thread sleep state under SMP environment. General usage
  • It is possible to perform critical section lock/unlock through CriticalSectionLock object after creating it.

Constructor & Destructor Documentation

PROUD_API Proud::CriticalSection::CriticalSection ( )

Initializes a critical section object.

PROUD_API Proud::CriticalSection::CriticalSection ( CriticalSectionSettings settings)

Initializes a critical section object.

PROUD_API Proud::CriticalSection::~CriticalSection ( void  )

Destroyer

  • There must be no thread occupying the critical section before the desruction.

Member Function Documentation

uint64_t Proud::CriticalSection::GetLastLockedThreadID ( )
returns ID of the thread where the last acquire (lock) is done.

This value does not set to zero if last unacquire (unlock) is done. You must set Proud.CriticalSectionSettings.m_updateLastLockedThreadID to true before using this function.

NOTE: on unix, this is pthread_t value. This may differ from thread ID shown in debugger.

bool Proud::CriticalSection::IsLocked ( ) const

Returns true if this is locked by any thread.

bool Proud::CriticalSection::IsLockedByCurrentThread ( ) const

Returns true if this is locked by current thread.

PROUD_API void Proud::CriticalSection::Lock ( )

The critical section is to be occupied by the thread calling this method.

PROUD_API bool Proud::CriticalSection::TryLock ( )

Use TryEnterCriticalSection rather than EnterCriticalSection.

Returns
If it locked successfully, it is true.
PROUD_API void Proud::CriticalSection::Unlock ( )

The critical section is to be relieved by the thread calling this method.

PROUD_API void Proud::CriticalSection::UnsafeLock ( )

TODO:translate needed. The critical section is to be occupied by the thread calling this method.