Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



Location: VersitTls.h
Link against: versit.lib

Class CVersitTlsData

class CVersitTlsData : public CBase;

Description

Versit thread local storage.

This class provides a performance improvement by allowing a CVersitUnicodeUtils instance to be shared between parsers operating in the same thread, so that a new instance does not have to be created for each parser. A pointer to the unicode utilities object is held in thread local storage: a single word (32bits) of data. Each unicode utilities object is managed by an instance of this class.

Every time a parser is created, CVersitParser::ConstructL() calls the CVersitTlsData constructor, and when the parser is destroyed the CVersitTlsData destructor is called. If a CVersitTlsData object exists, the constructor returns a pointer to it, otherwise a new one is constructed. The CVersitTlsData object is only destroyed when no more parsers refer to it: a count is kept, which is incremented every time the constructor is called and decremented each time the destructor is called, and the object is only destroyed when the count reaches zero.

This class provides an additional major performance improvement if you are sequentially constructing and destructing multiple parsers. By default, when the count of parsers reaches zero, the thread local storage object is destroyed (even if the thread has not finished). However, by using the technique described below, the thread local storage object, and therefore the unicode utilities object, can be made to persist, significantly reducing the overhead of sequentially constructing and destructing parsers.

The constructor needs to be called an extra time before creating any parsers, and the destructor needs to be called an extra time once the parsers have been destroyed. This has the effect of adding one to the reference count so that during all the parser construction and deletion the count never hits zero, which would trigger the TLS object's destruction.

This can be implemented as follows:

1. Create a thread local storage data class instance as follows:

CVersitTlsData* versitTLS = CVersitTlsData::VersitTlsDataL(); 

2. Create and delete the parsers.

3. Delete the Thread Local Storage Data class instance:

delete versitTLS; 

Derivation

Members

Defined in CVersitTlsData:
AdditionalStorage(), CloseVersitTlsData(), UnicodeUtils(), VersitTlsDataClose(), VersitTlsDataL()

Inherited from CBase:
Delete(), Extension_(), operator new()


Member functions


VersitTlsDataL()

static IMPORT_C CVersitTlsData &VersitTlsDataL();

Description

Returns a reference to the current Thread Local Storage (TLS) object or, if there isn't one, it creates one.

If a new TLS object is being created, the object also creates (and owns) a Unicode utilities object, and creates a Unicode converter using this object.

If creating a new object, it calls the CVersitUnicodeUtils constructor followed by CVersitUnicodeUtils::CreateConverterL().

Return value

CVersitTlsData &

The current Thread Local Storage object.


CloseVersitTlsData()

static IMPORT_C void CloseVersitTlsData();

Description


VersitTlsDataClose()

IMPORT_C void VersitTlsDataClose();

Description

Frees all resources owned by the object if there are no parsers left (i.e. created and not destroyed), prior to its destruction.


UnicodeUtils()

inline CVersitUnicodeUtils &UnicodeUtils();

Description

Returns a pointer to the current Unicode utilities object.

Return value

CVersitUnicodeUtils &

A pointer to the current Unicode utilities object.


AdditionalStorage()

inline CVersitAdditionalStorage &AdditionalStorage();

Description

Returns a pointer to the additional property storage object.

Return value

CVersitAdditionalStorage &

A pointer to the additional property storage.