Den::CCommonPitBoss Class Reference

class Den::CCommonPitBoss : public CBase
The PitBoss has responsibility for global resources and gross error handling (panics, etc). The Pit Boss thread must be started by the Configurator before any worker threads. The instance loading it must be the only one having the WorkerId 0 (TWorkerThreadInfo::EMainThread). The PitBoss has two main responsibilities:
  1. Maintain global data structures, accessible to all Workers to which the PitBoss pointer is published (through the TWorkerMainIntroductionMsg). Mostly the workers will access this data using PitBoss access functions which are thread-safe, taking special measures to guarantee this where needed.

  2. Manage Worker thread start and death: Registering Workers and do a best effort cleanup if they die due to some error condition.

Apart from these, the PitBoss also provides some minor but important services. For example as all instances can have their own heap sometimes it happens that one Worker needs to do something that might cause allocation or freeing on another workers heap, such as inserting a sub-session into a Dealers session. So the PitBoss offer a function that can determine whether a different heap is needed (maybe the two workers have different heaps, maybe they share one heap) and does the switch. It also has AddSubSession() and RemoveSubSession() methods used by the Player, assuring this happens on the right heap.

Inherits from

Nested Classes and Structures

Public Member Functions
~CCommonPitBoss()
voidAddPendingIntroductionResponse()
IMPORT_C TIntAddSubSession(CWorkerSubSession *, CWorkerSession *, TInt &)
IMPORT_C voidBindMessageReceived(const CommsFW::TCFModuleName &, CommsFW::TWorkerId)
IMPORT_C voidBroadcastConfigurationComplete(TConfigurationCompletionType)
voidCompleteWorkerThreadCleanup(CommsFW::TWorkerId)
IMPORT_C voidConstructL()
CCommonDealer *Dealer(const TWorkerThreadRegister &)
CCommonDealer *Dealer(CommsFW::TWorkerId)
IMPORT_C TIntDoCreateRedShirt(RThread &, CommsFW::TWorkerId, CCommonWorkerThread &)
voidDoOnCPMsConfigured()
voidDoOnPeerDeath(CommsFW::TWorkerId)
IMPORT_C TBoolFindOptimalDealer(CommsFW::TWorkerId, CCommonWorkerDealer *&)
voidFreeWorkerReferences(CommsFW::TWorkerId)
IMPORT_C CCommonDealer *GetDealer(CommsFW::TWorkerId)
IMPORT_C CCommonPlayer *GetPlayer(const TWorkerIntroductionMsg &)
IMPORT_C voidHandleWorkerCleanupCompletionByPeer(CommsFW::TWorkerId, CommsFW::TWorkerId)
IMPORT_C TBoolIsShuttingDown()
IMPORT_C RAllocator *MaybeSwitchHeap(CommsFW::TWorkerId)
IMPORT_C TBoolModuleConfigurationComplete()
TInt NextSessionId()
TSessionUniqueId NextSessionUniqueId()
TSubSessionUniqueId NextSubSessionUniqueId()
IMPORT_C voidOnCPMsConfigured()
IMPORT_C voidOnPeerDeath(CommsFW::TWorkerId)
CCommonWorkerThread *OwnerThread()
IMPORT_C voidPeerWorkerExiting(CommsFW::TWorkerId)
CCommonPlayer *Player(const TWorkerThreadRegister &)
CCommonPlayer *Player(CommsFW::TWorkerId)
IMPORT_C voidPostMessage(CommsFW::TWorkerId, CommsFW::TCFMessage &)
IMPORT_C voidProcessWorkerIntroductionL(const TWorkerIntroductionMsg &)
TUid PropertyKey()
IMPORT_C const RThread &RThreadRef(CommsFW::TWorkerId)
voidReleaseImmediateShutdownPresent()
voidRemovePendingIntroductionResponse()
IMPORT_C voidRemoveSubSession(TInt, CWorkerSession *)
IMPORT_C TBoolResolvePlayerRoleToId(const TPlayerRole &, CommsFW::TWorkerId &)
IMPORT_C TBoolResolveWorkerNameToId(const TDesC8 &, CommsFW::TWorkerId &)
IMPORT_C voidSessionShutdownComplete()
IMPORT_C voidSetFailNextForAllHeaps(TInt)
voidSetImmediateShutdownPresent()
voidShutdownIfReady()
voidStartShutdown()
TBool TestAndLockImmediateShutdownPresent()
IMPORT_C TBoolTestFailNextForAllHeaps()
IMPORT_C TBoolTestImmediateShutdownPresent()
CWorkerDataGlobals &WorkerDataGlobals()
IMPORT_C TBoolWorkerExists(CommsFW::TWorkerId)
CCommonWorkerThread &WorkerThread()
Protected Member Functions
CCommonPitBoss(CCommonWorkerThread *)
voidDoFreeWorkerReferences(CommsFW::TWorkerId)
voidDoProcessWorkerIntroductionL(const TWorkerIntroductionMsg &)
Inherited Functions
CBase::CBase()
CBase::Delete(CBase *)
CBase::Extension_(TUint,TAny *&,TAny *)
CBase::operator new(TUint)
CBase::operator new(TUint,TAny *)
CBase::operator new(TUint,TLeave)
CBase::operator new(TUint,TLeave,TUint)
CBase::operator new(TUint,TUint)
CBase::~CBase()
Protected Attributes
CConfigurationLevelMonitor *iConfLevelMonitor
RForsakenHeapList iForsakenHeapList
RWorkerLock iImmediateShutdownLock
TBool iImmediateShutdownMark
TUint iNextUniqueId
CCommonWorkerThread *iOwnerThread
TBool iPeerShutdownComplete
TInt iPendingIntroResponses
TUid iPropertyKey
TBool iSessionShutdownComplete
TBool iShuttingDown
CWorkerDataGlobals *iWorkerDataGlobals

Constructor & Destructor Documentation

CCommonPitBoss(CCommonWorkerThread *)

IMPORT_CCCommonPitBoss(CCommonWorkerThread *aOwnerThread)[protected]

Parameters

CCommonWorkerThread * aOwnerThread

~CCommonPitBoss()

IMPORT_C~CCommonPitBoss()

Member Functions Documentation

AddPendingIntroductionResponse()

voidAddPendingIntroductionResponse()

AddSubSession(CWorkerSubSession *, CWorkerSession *, TInt &)

IMPORT_C TIntAddSubSession(CWorkerSubSession *aSubSession,
CWorkerSession *aSession,
TInt &aHandle
)

Called by any Player/thread to add a sub-session to a session. It will switch the local heap to that of the peer before performing operations on the session pointer. It is essential that the session lock is used around this call. CSubSessionIx::Lock CSubSessionIx::UnLock

Parameters

CWorkerSubSession * aSubSession
CWorkerSession * aSession
TInt & aHandle

BindMessageReceived(const CommsFW::TCFModuleName &, CommsFW::TWorkerId)

IMPORT_C voidBindMessageReceived(const CommsFW::TCFModuleName &aPeerName,
CommsFW::TWorkerIdaPeerId
)

Parameters

const CommsFW::TCFModuleName & aPeerName
CommsFW::TWorkerId aPeerId

BroadcastConfigurationComplete(TConfigurationCompletionType)

IMPORT_C voidBroadcastConfigurationComplete(TConfigurationCompletionTypeaType)

CompleteWorkerThreadCleanup(CommsFW::TWorkerId)

voidCompleteWorkerThreadCleanup(CommsFW::TWorkerIdaWorkerId)

Parameters

CommsFW::TWorkerId aWorkerId

ConstructL()

IMPORT_C voidConstructL()

Dealer(const TWorkerThreadRegister &)

CCommonDealer *Dealer(const TWorkerThreadRegister &aRegister)[inline]

Parameters

const TWorkerThreadRegister & aRegister

Dealer(CommsFW::TWorkerId)

CCommonDealer *Dealer(CommsFW::TWorkerIdaWorkerId)const

Parameters

CommsFW::TWorkerId aWorkerId

DoCreateRedShirt(RThread &, CommsFW::TWorkerId, CCommonWorkerThread &)

IMPORT_C TIntDoCreateRedShirt(RThread &aRedShirt,
CommsFW::TWorkerIdaWorkerId,
CCommonWorkerThread &aDeadWorker
)[virtual]

Parameters

RThread & aRedShirt
CommsFW::TWorkerId aWorkerId
CCommonWorkerThread & aDeadWorker

DoFreeWorkerReferences(CommsFW::TWorkerId)

voidDoFreeWorkerReferences(CommsFW::TWorkerIdaWorkerId)[protected, pure virtual]

Parameters

CommsFW::TWorkerId aWorkerId

DoOnCPMsConfigured()

voidDoOnCPMsConfigured()[pure virtual]

DoOnPeerDeath(CommsFW::TWorkerId)

voidDoOnPeerDeath(CommsFW::TWorkerIdaWorkerId)[pure virtual]

Parameters

CommsFW::TWorkerId aWorkerId

DoProcessWorkerIntroductionL(const TWorkerIntroductionMsg &)

voidDoProcessWorkerIntroductionL(const TWorkerIntroductionMsg &aMsg)[protected, pure virtual]

Parameters

const TWorkerIntroductionMsg & aMsg

FindOptimalDealer(CommsFW::TWorkerId, CCommonWorkerDealer *&)

IMPORT_C TBoolFindOptimalDealer(CommsFW::TWorkerIdaWorkerId,
CCommonWorkerDealer *&aDealer
)

Parameters

CommsFW::TWorkerId aWorkerId
CCommonWorkerDealer *& aDealer

FreeWorkerReferences(CommsFW::TWorkerId)

voidFreeWorkerReferences(CommsFW::TWorkerIdaWorkerId)

Parameters

CommsFW::TWorkerId aWorkerId

GetDealer(CommsFW::TWorkerId)

IMPORT_C CCommonDealer *GetDealer(CommsFW::TWorkerIdaId)

Parameters

CommsFW::TWorkerId aId

GetPlayer(const TWorkerIntroductionMsg &)

IMPORT_C CCommonPlayer *GetPlayer(const TWorkerIntroductionMsg &aMsg)

Parameters

const TWorkerIntroductionMsg & aMsg

HandleWorkerCleanupCompletionByPeer(CommsFW::TWorkerId, CommsFW::TWorkerId)

IMPORT_C voidHandleWorkerCleanupCompletionByPeer(CommsFW::TWorkerIdaWorkerId,
CommsFW::TWorkerIdaPeerId
)

Parameters

CommsFW::TWorkerId aWorkerId
CommsFW::TWorkerId aPeerId

IsShuttingDown()

IMPORT_C TBoolIsShuttingDown()const

MaybeSwitchHeap(CommsFW::TWorkerId)

IMPORT_C RAllocator *MaybeSwitchHeap(CommsFW::TWorkerIdaForeignWorkerId)

Parameters

CommsFW::TWorkerId aForeignWorkerId

ModuleConfigurationComplete()

IMPORT_C TBoolModuleConfigurationComplete()const

NextSessionId()

TInt NextSessionId()

NextSessionUniqueId()

TSessionUniqueId NextSessionUniqueId()[inline]

NextSubSessionUniqueId()

TSubSessionUniqueId NextSubSessionUniqueId()[inline]

OnCPMsConfigured()

IMPORT_C voidOnCPMsConfigured()

The PitBoss monitors the Comms Configurator sequence level and when the core components have been configured (this includes ESock) this method is called to delete any data structures used only during startup of ESock. CConfigurationLevelMonitor CPitBoss::iPendingIntroResponses

OnPeerDeath(CommsFW::TWorkerId)

IMPORT_C voidOnPeerDeath(CommsFW::TWorkerIdaWorkerId)

Parameters

CommsFW::TWorkerId aWorkerId

OwnerThread()

CCommonWorkerThread *OwnerThread()[inline]

PeerWorkerExiting(CommsFW::TWorkerId)

IMPORT_C voidPeerWorkerExiting(CommsFW::TWorkerIdaWorker)

Parameters

CommsFW::TWorkerId aWorker

Player(const TWorkerThreadRegister &)

CCommonPlayer *Player(const TWorkerThreadRegister &aRegister)[inline]

Parameters

const TWorkerThreadRegister & aRegister

Player(CommsFW::TWorkerId)

CCommonPlayer *Player(CommsFW::TWorkerIdaWorkerId)const

Parameters

CommsFW::TWorkerId aWorkerId

PostMessage(CommsFW::TWorkerId, CommsFW::TCFMessage &)

IMPORT_C voidPostMessage(CommsFW::TWorkerIdaWorkerId,
CommsFW::TCFMessage &aMessage
)

Parameters

CommsFW::TWorkerId aWorkerId
CommsFW::TCFMessage & aMessage

ProcessWorkerIntroductionL(const TWorkerIntroductionMsg &)

IMPORT_C voidProcessWorkerIntroductionL(const TWorkerIntroductionMsg &aMsg)

Used during binding when the PitBoss receives a introduction response message from a worker. The PitBoss will set-up housekeeping datastructures for the worker and add the supported protocols to its list of protocol pairings. TWorkerMsg::EMainIntroductionResp

Parameters

const TWorkerIntroductionMsg & aMsg

PropertyKey()

TUid PropertyKey()[inline]

RThreadRef(CommsFW::TWorkerId)

IMPORT_C const RThread &RThreadRef(CommsFW::TWorkerIdaWorkerId)const

Parameters

CommsFW::TWorkerId aWorkerId

ReleaseImmediateShutdownPresent()

voidReleaseImmediateShutdownPresent()const

RemovePendingIntroductionResponse()

voidRemovePendingIntroductionResponse()

RemoveSubSession(TInt, CWorkerSession *)

IMPORT_C voidRemoveSubSession(TIntaHandle,
CWorkerSession *aSession
)

Called by any Player/thread to remove a sub-session from a session. It will switch the local heap to that of the peer before performing operations on the session pointer. It is essential that the session lock is used around this call. CSubSessionIx::Lock CSubSessionIx::UnLock

Parameters

TInt aHandle
CWorkerSession * aSession

ResolvePlayerRoleToId(const TPlayerRole &, CommsFW::TWorkerId &)

IMPORT_C TBoolResolvePlayerRoleToId(const TPlayerRole &aRoleId,
CommsFW::TWorkerId &aWorkerId
)const

Resolve a PlayerRole to its thread id (module names are far less volatile than thread assignments which in the future may become highly dynamic. So module names are used to couple tier ids to threads

Parameters

const TPlayerRole & aRoleId
CommsFW::TWorkerId & aWorkerId

ResolveWorkerNameToId(const TDesC8 &, CommsFW::TWorkerId &)

IMPORT_C TBoolResolveWorkerNameToId(const TDesC8 &aWorkerName,
CommsFW::TWorkerId &aWorkerId
)const

Resolve a Worker thread's CFModule name to its thread id (module names are far less volatile than thread assignments which in the future may become highly dynamic. So module names are used to couple tier ids to threads

Parameters

const TDesC8 & aWorkerName
CommsFW::TWorkerId & aWorkerId

SessionShutdownComplete()

IMPORT_C voidSessionShutdownComplete()

SetFailNextForAllHeaps(TInt)

IMPORT_C voidSetFailNextForAllHeaps(TIntaFailNext)

Parameters

TInt aFailNext

SetImmediateShutdownPresent()

voidSetImmediateShutdownPresent()

ShutdownIfReady()

voidShutdownIfReady()

StartShutdown()

voidStartShutdown()

TestAndLockImmediateShutdownPresent()

TBool TestAndLockImmediateShutdownPresent()const

Immediate shutdowns expose a number of additional race risks; in the face of one happening to any thread at all we stop attempting certain kinds of cleanup. This should be acceptable behaviour since at it will be the whole of ESock shutting down. To avoid races between the testing and setting of this state, testing for it gains a lock which must be explicitly released. CPitBoss::ReleaseImmediateShutdownPresent()

TestFailNextForAllHeaps()

IMPORT_C TBoolTestFailNextForAllHeaps()const

TestImmediateShutdownPresent()

IMPORT_C TBoolTestImmediateShutdownPresent()const

Tests whether immediate shutdown is signaled. This function does not lock and is used where this knowledge is desired but no action is taken that might race with other threads. CPitBoss::TestAndLockImmediateShutdownPresent() CPitBoss::ReleaseImmediateShutdownPresent()

WorkerDataGlobals()

CWorkerDataGlobals &WorkerDataGlobals()const [inline]

WorkerExists(CommsFW::TWorkerId)

IMPORT_C TBoolWorkerExists(CommsFW::TWorkerIdaId)const

Parameters

CommsFW::TWorkerId aId

WorkerThread()

CCommonWorkerThread &WorkerThread()const [inline]

Member Data Documentation

CConfigurationLevelMonitor * iConfLevelMonitor

CConfigurationLevelMonitor *iConfLevelMonitor[protected]

Monitor configuration level to know when it is safe to delete data used solely during startup/binding. Note that if we should support loading new Socket Server modules at run time, sometime after system start, this will need to be changed so the list is always available to new modules.

RForsakenHeapList iForsakenHeapList

RForsakenHeapList iForsakenHeapList[protected]

RWorkerLock iImmediateShutdownLock

RWorkerLock iImmediateShutdownLock[protected]

This is used by Worker threads (as well as ESock_Main) during immediate shutdown. As a Worker could potentially delete a sub-session at the same time as the Dealer trying to mark it orphaned, these two operations need to be protected during immediate shutdown (but not normally).

TBool iImmediateShutdownMark

TBool iImmediateShutdownMark[protected]

Set ETrue when immediate shutdown is received from the RootServer.

TUint iNextUniqueId

TUint iNextUniqueId[protected]

Session/subsession unique id counter. This value represents a next (free) id that will be assigned to a newly created CWorkerSubSession object.

CCommonWorkerThread * iOwnerThread

CCommonWorkerThread *iOwnerThread[protected]

TBool iPeerShutdownComplete

TBool iPeerShutdownComplete[protected]

Set ETrue when all Worker threads have finished tidying up during a shut down procedure. The ESock_Main instance will only shut down when this is ETrue.

TInt iPendingIntroResponses

TInt iPendingIntroResponses[protected]

Incremented when a request to bind to another instance has been received and decremented when a binding is complete. When the reference configurator configuration level have reached the point signifying that all core components have been configured and this TInt is 0, it is safe to delete data structures used only during startup. OnCoreComponentsConfigured()

TUid iPropertyKey

TUid iPropertyKey[protected]

TBool iSessionShutdownComplete

TBool iSessionShutdownComplete[protected]

Set ETrue when immediate shutdown is received by ESock_Main from the RootServer or if optional/graceful shutdown has been received at some point and the last session is closed.

TBool iShuttingDown

TBool iShuttingDown[protected]

ETrue if the PitBoss is in the process of shutting down. Set when optional or graceful shutdown is received by ESock_Main from the RootServer.

CWorkerDataGlobals * iWorkerDataGlobals

CWorkerDataGlobals *iWorkerDataGlobals[protected]