Public Types | Public Member Functions

CriticalSection Class Reference

A mutex class. More...

Inherited by ArrayAllocationBase< TestResult *, CriticalSection >.

List of all members.

Public Types

typedef GenericScopedLock
< CriticalSection
ScopedLockType
 Provides the type of scoped lock to use with a CriticalSection.
typedef GenericScopedUnlock
< CriticalSection
ScopedUnlockType
 Provides the type of scoped unlocker to use with a CriticalSection.
typedef GenericScopedTryLock
< CriticalSection
ScopedTryLockType
 Provides the type of scoped try-locker to use with a CriticalSection.

Public Member Functions

 CriticalSection () noexcept
 Creates a CriticalSection object.
 ~CriticalSection () noexcept
 Destructor.
void enter () const noexcept
 Acquires the lock.
bool tryEnter () const noexcept
 Attempts to lock this critical section without blocking.
void exit () const noexcept
 Releases the lock.

Detailed Description

A mutex class.

A CriticalSection acts as a re-entrant mutex lock. The best way to lock and unlock one of these is by using RAII in the form of a local ScopedLock object - have a look through the codebase for many examples of how to do this.

See also:
ScopedLock, ScopedTryLock, ScopedUnlock, SpinLock, ReadWriteLock, Thread, InterProcessLock

Member Typedef Documentation

Provides the type of scoped lock to use with a CriticalSection.

Provides the type of scoped unlocker to use with a CriticalSection.

Provides the type of scoped try-locker to use with a CriticalSection.


Constructor & Destructor Documentation

CriticalSection::CriticalSection (  )

Creates a CriticalSection object.

CriticalSection::~CriticalSection (  )

Destructor.

If the critical section is deleted whilst locked, any subsequent behaviour is unpredictable.


Member Function Documentation

void CriticalSection::enter (  ) const

Acquires the lock.

If the lock is already held by the caller thread, the method returns immediately. If the lock is currently held by another thread, this will wait until it becomes free.

It's strongly recommended that you never call this method directly - instead use the ScopedLock class to manage the locking using an RAII pattern instead.

See also:
exit, tryEnter, ScopedLock
bool CriticalSection::tryEnter (  ) const

Attempts to lock this critical section without blocking.

This method behaves identically to CriticalSection::enter, except that the caller thread does not wait if the lock is currently held by another thread but returns false immediately.

Returns:
false if the lock is currently held by another thread, true otherwise.
See also:
enter
void CriticalSection::exit (  ) const

Releases the lock.

If the caller thread hasn't got the lock, this can have unpredictable results.

If the enter() method has been called multiple times by the thread, each call must be matched by a call to exit() before other threads will be allowed to take over the lock.

See also:
enter, ScopedLock

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines