Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32std.h
Link against: euser.lib

Class RCriticalSection

RCriticalSection

Support

Supported from 5.0

Description

Handle to a critical section.

A critical section object is implemented using a semaphore. The class RCriticalSection inherits privately from RSemaphore as a matter of implementation and this is, in effect, equivalent to using a semaphore.

The public functions of RSemaphore are not part of the API of this class.

As with all handles, they should be closed after use. This class provides the necessary Close() function, which should be called when the handle is no longer required.

Derivation

RCriticalSectionHandle to a critical section
RHandleBaseHandle to an object
RSemaphoreProvides a handle to a semaphore

Defined in RCriticalSection:
Close(), CreateLocal(), IsBlocked(), RCriticalSection(), Signal(), Wait()

Inherited from RHandleBase:
Duplicate(), Handle(), SetHandle()

Inherited from RSemaphore:
Count(), CreateGlobal(), Open(), OpenGlobal()


Construction and destruction


RCriticalSection()

RCriticalSection();

Description

Constructs the object.

The constructor exists to initialise private data within this handle; it does not create the critical section object.

[Top]


Create a critical section


CreateLocal()

TInt CreateLocal(TOwnerType aType=EOwnerProcess);

Description

Creates a critical section and opens this handle to that critical section.

The Kernel side object representing the critical section is unnamed. It is, therefore, local to the calling process. The handle can be used directly by any thread within the calling process, but no other RCriticalSection object can open a duplicate handle.

By default, ownership of this critical section handle is vested in the current process, but can be vested in the current thread by passing EOwnerThread as the second parameter to this function.

Parameters

TOwnerType aType

An enumeration whose enumerators define the ownership of this critical section handle. If not explicitly specified, EOwnerProcess is taken as default.

Return value

TInt

KErrNone if successful otherwise another of the system-wide error codes

[Top]


Close a critical section


Close()

void Close();

Description

Closes the handle to the critical section object.

As a critical section object is implemented using a semaphore, this has the effect of closing the handle to the semaphore.

[Top]


Controlling access to the critical section


Wait()

void Wait();

Description

Waits for access to the critical section.

If no other thread is in the critical section, control returns immediately and the current thread can continue into the section.

If another thread is already in the critical section, the current thread is marked as waiting (on a semaphore); the current thread is added to the end of a FIFO queue of threads maintained by this critical section.


Signal()

void Signal();

Description

Signals an exit from the critical section.

A thread calls Signal() when it exits from the critical section. The first thread waiting on the critical section’s queue of threads is removed from that queue and, provided that it is not suspended for any other reason, is marked as ready to run. That thread will, therefore, be the next to proceed into the critical section.


IsBlocked()

TBool IsBlocked() const;

Description

Tests whether the critical section is occupied by another thread.

Return value

TBool

True, if the critical section is occupied by another thread. False, otherwise.