STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Concurrency::critical_section Class Reference

A non-reentrant mutex which is explicitly aware of the Concurrency Runtime. More...

#include <concrt.h>

Classes

class  scoped_lock
 An exception safe RAII wrapper for a critical_section object. More...
 

Public Types

typedef critical_sectionnative_handle_type
 A reference to a critical_section object. More...
 

Public Member Functions

_CONCRTIMP critical_section ()
 Constructs a new critical section. More...
 
_CONCRTIMP ~critical_section ()
 Destroys a critical section. More...
 
_CONCRTIMP void lock ()
 Acquires this critical section. More...
 
_CONCRTIMP bool try_lock ()
 Tries to acquire the lock without blocking. More...
 
_CONCRTIMP bool try_lock_for (unsigned int _Timeout)
 Tries to acquire the lock without blocking for a specific number of milliseconds. More...
 
_CONCRTIMP void unlock ()
 Unlocks the critical section. More...
 
_CONCRTIMP native_handle_type native_handle ()
 Returns a platform specific native handle, if one exists. More...
 
void _Flush_current_owner ()
 Guarantees that if any context holds the lock at the time the method is called, that context has released the lock before this method returns. More...
 
bool _Acquire_lock (void *_PLockingNode, bool _FHasExternalNode)
 Acquires this critical section given a specific node to lock. More...
 

Private Member Functions

void _Switch_to_active (void *_PLockingNode)
 The node allocated on the stack never really owns the lock because it would go out of scope and the insides would not be visible in unlock() where it could potentially need to unblock the next in the queue. Instead, its state is transferred to the internal node which is used as a scratch node. More...
 
 critical_section (const critical_section &)
 Hide copy constructor for a critical section More...
 
critical_sectionoperator= (const critical_section &)
 Hide assignment operator for a critical section More...
 

Private Attributes

_CONCRT_BUFFER _M_activeNode [(4 *sizeof(void *)+2 *sizeof(unsigned int)+sizeof(_CONCRT_BUFFER)-1)/sizeof(_CONCRT_BUFFER)]
 
void *volatile _M_pHead
 
void *volatile _M_pTail
 

Detailed Description

A non-reentrant mutex which is explicitly aware of the Concurrency Runtime.

For more information, see Synchronization Data Structures.

See also
reader_writer_lock Class

Member Typedef Documentation

A reference to a critical_section object.

Constructor & Destructor Documentation

_CONCRTIMP Concurrency::critical_section::critical_section ( )

Constructs a new critical section.

_CONCRTIMP Concurrency::critical_section::~critical_section ( )

Destroys a critical section.

It is expected that the lock is no longer held when the destructor runs. Allowing the critical section to destruct with the lock still held results in undefined behavior.

Concurrency::critical_section::critical_section ( const critical_section )
private

Hide copy constructor for a critical section

Member Function Documentation

bool Concurrency::critical_section::_Acquire_lock ( void _PLockingNode,
bool  _FHasExternalNode 
)

Acquires this critical section given a specific node to lock.

Parameters
_PLockingNodeThe node that needs to own the lock.
_FHasExternalNodeAn indication if the node being locked is external to the critical_section.

If the lock is already held by the calling context, an .improper_lock exception will be thrown.

void Concurrency::critical_section::_Flush_current_owner ( )

Guarantees that if any context holds the lock at the time the method is called, that context has released the lock before this method returns.

If no context holds the lock at the instant this method is called, it returns instantly.

void Concurrency::critical_section::_Switch_to_active ( void _PLockingNode)
private

The node allocated on the stack never really owns the lock because it would go out of scope and the insides would not be visible in unlock() where it could potentially need to unblock the next in the queue. Instead, its state is transferred to the internal node which is used as a scratch node.

Parameters
_PLockingNodeThe node that needs to own the lock.
_CONCRTIMP void Concurrency::critical_section::lock ( )

Acquires this critical section.

It is often safer to utilize the scoped_lock construct to acquire and release a critical_section object in an exception safe way.

If the lock is already held by the calling context, an improper_lock exception will be thrown.

See also
critical_section::unlock Method, critical_section::scoped_lock Class
_CONCRTIMP native_handle_type Concurrency::critical_section::native_handle ( )

Returns a platform specific native handle, if one exists.

Returns
A reference to the critical section.

A critical_section object is not associated with a platform specific native handle for the Windows operating system. The method simply returns a reference to the object itself.

critical_section& Concurrency::critical_section::operator= ( const critical_section )
private

Hide assignment operator for a critical section

_CONCRTIMP bool Concurrency::critical_section::try_lock ( )

Tries to acquire the lock without blocking.

Returns
If the lock was acquired, the value true; otherwise, the value false.
See also
critical_section::unlock Method
_CONCRTIMP bool Concurrency::critical_section::try_lock_for ( unsigned int  _Timeout)

Tries to acquire the lock without blocking for a specific number of milliseconds.

Parameters
_TimeoutThe number of milliseconds to wait before timing out.
Returns
If the lock was acquired, the value true; otherwise, the value false.
See also
critical_section::unlock Method
_CONCRTIMP void Concurrency::critical_section::unlock ( )

Unlocks the critical section.

See also
critical_section::lock Method, critical_section::try_lock Method

Member Data Documentation

_CONCRT_BUFFER Concurrency::critical_section::_M_activeNode[(4 *sizeof(void *)+2 *sizeof(unsigned int)+sizeof(_CONCRT_BUFFER)-1)/sizeof(_CONCRT_BUFFER)]
private
void* volatile Concurrency::critical_section::_M_pHead
private
void* volatile Concurrency::critical_section::_M_pTail
private

The documentation for this class was generated from the following file: