CBS_CriticalSection Class Reference

Implements a tracked Critical Section class.. More...

List of all members.

Public Member Functions

 CBS_CriticalSection (CBS_Trace *pTrace, BOOL bShowAllEnterNLeave=FALSE)
void DeleteBSCriticalSection ()
void EnterBSCriticalSection (LPCSTR lpComment, LPCSTR lpFileName, UINT nLine)
void FreeResources ()
DWORD GetOwnerThreadID ()
CBS_TraceGetTrace ()
void InitializeBSCriticalSection (LPCTSTR lpFileName, UINT nLine)
BOOL IsLocked ()
void LeaveBSCriticalSection (LPCSTR lpComment, LPCSTR lpFileName, UINT nLine)
BOOL SetShowAllEnterNLeave (BOOL bSet)
CBS_TraceSetTrace (CBS_Trace *pTrace)
virtual ~CBS_CriticalSection ()

Protected Attributes

LPVOID m_pCSData
 Private member for internal use.


Detailed Description

Implements a tracked Critical Section class..

Author:
Dror Otmi
Date:
12.10.2003
Version:
V 1.0 Initial version
This class monitors the synchronization object. It registers the critical section entring and leaving in the resource track. If there is suspicion for a bad synchronization (e.g. application shutdown while threads stil wait to enter a critical section), the user will be alert latest when the application shutdown.


Constructor & Destructor Documentation

CBS_CriticalSection::CBS_CriticalSection CBS_Trace pTrace,
BOOL  bShowAllEnterNLeave = FALSE
 

Constructur of CBS_CriticalSection class.

Parameters:
pTrace The trace object into which the messages will be reported
bShowAllEnterNLeave If to show all enter and leave, if this parameter is FALSE the registred entries will be deleted from the resource track object, when the last thread left the critical section. Default = FALSE.
Note:
Beware with using bShowAllEnterNLeave, if it is set to TRUE it might cause memory problems since the registered memory is never freed!!!

CBS_CriticalSection::~CBS_CriticalSection  )  [virtual]
 

Destroy the object.


Member Function Documentation

void CBS_CriticalSection::DeleteBSCriticalSection  ) 
 

Deletes the critical section. If there are threads waiting for the critical section, it will be reported to the trace (if the trace is valid) and the critical section will not be removed from the Resource Track object, so when the application will exit it will be reported. If the application wants to use the object again, it must call InitializeCriticalSection().

Returns:
Nothing

void CBS_CriticalSection::EnterBSCriticalSection LPCSTR  lpComment,
LPCSTR  lpFileName,
UINT  nLine
 

Enters the critical section. This function is overwritten with the following macro:
#define EnterCriticalSection( ) EnterCriticalSection( __FILE__, __LINE__ )
Before the function tries to enter the critical section it will register the entring attampt in the Resource Track. The function will assert if the critical section is not initialized.

Parameters:
lpComment An application defined comment that will be writen to the Resource Track.
lpFileName The file in which the call was made
nLine The line in lpFileName.
Returns:
Nothing

void CBS_CriticalSection::FreeResources  ) 
 

Free the resources allocated by the current object. This method should be invoked only once, it will assert if it called more then once. The object can not be used after this function is invoked.

Returns:
Nothing

DWORD CBS_CriticalSection::GetOwnerThreadID  ) 
 

Get the ID of the thread that currently own the critical section.

Returns:
The the thread ID of the critical section's owner or 0 if it has no owner.

CBS_Trace * CBS_CriticalSection::GetTrace  ) 
 

See return.

Returns:
The pointer of the trace associated with the current object.

void CBS_CriticalSection::InitializeBSCriticalSection LPCTSTR  lpFileName,
UINT  nLine
 

Initializes the critical section object.

Note:
This function is declared as a macro (InitializeBSCriticalSection( __FILE__, __LINE__ )), so the arguments are automatically inserted.
Parameters:
lpFileName The file calling this function
nLine The line from which the function is called
Returns:
Nothing

BOOL CBS_CriticalSection::IsLocked  ) 
 

Checks if the critical section is locked for the calling thread.

Returns:
The function return TRUE if the critical section is locked for the calling thread.

void CBS_CriticalSection::LeaveBSCriticalSection LPCSTR  lpComment,
LPCSTR  lpFileName,
UINT  nLine
 

Leave the critical section. This function is overwritten with the following macro:
#define LeaveCriticalSection( ) LeaveCriticalSection( __FILE__, __LINE__ )
The function will assert if it is invoked by a thread that does not own the critical section. If the thread releases the ownership of critical section, all references in the Resource Trace of that thread will be deleted (if the ShowAllEnterNLeave flag is FALSE).

Parameters:
lpComment application defined comment that will be sent to the Resource Track.
lpFileName The file name in which the call was made.
nLine The line in lpFileName.
Returns:
Nothing

BOOL CBS_CriticalSection::SetShowAllEnterNLeave BOOL  bSet  ) 
 

Change the value of ShowAllEnterNLeave flag

Parameters:
bSet The value to set to ShowAllEnterNLeave flag.
Returns:
The old value of ShowAllEnterNLeave.
Note:
Setting ShowAllEnterNLeave to TRUE might cause a memory problem since the memory allocated for the comments in each enter or leave is never freed!!!

CBS_Trace * CBS_CriticalSection::SetTrace CBS_Trace pTrace  ) 
 

Sets a trace object to the current object.

Parameters:
pTrace A pointer to the trace object.
Returns:
The pointer of the the old trace object associated with the current object.
Bitspot AG


Bitspot AG
Rietlistrasse 1
CH-6345 Neuheim

Bitspot AG Logo

Phone:

+41 41 755 11 22

Fax:

+41 41 755 11 31

e-mail:

mail@bitspot.com

Web:

www.bitspot.com