epoc32/include/versittls.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
#ifndef __VERSITTLS_H__
williamr@2
    17
#define __VERSITTLS_H__
williamr@2
    18
williamr@2
    19
// System includes
williamr@2
    20
#include <e32base.h>
williamr@2
    21
#include <charconv.h>
williamr@2
    22
williamr@2
    23
#include <vutil.h>
williamr@2
    24
williamr@2
    25
class CVersitTimer;
williamr@2
    26
class CVersitAdditionalStorage;
williamr@2
    27
williamr@2
    28
class CVersitTlsData : public CBase
williamr@2
    29
/** Versit thread local storage.
williamr@2
    30
williamr@2
    31
This class provides a performance improvement by allowing a CVersitUnicodeUtils 
williamr@2
    32
instance to be shared between parsers operating in the same thread, so that 
williamr@2
    33
a new instance does not have to be created for each parser. A pointer to the 
williamr@2
    34
unicode utilities object is held in thread local storage: a single word (32bits) 
williamr@2
    35
of data. Each unicode utilities object is managed by an instance of this class.
williamr@2
    36
williamr@2
    37
Every time a parser is created, CVersitParser::ConstructL() calls the 
williamr@2
    38
CVersitTlsData constructor, and when the parser is destroyed the CVersitTlsData 
williamr@2
    39
destructor is called. If a CVersitTlsData object exists, the constructor 
williamr@2
    40
returns a pointer to it, otherwise a new one is constructed. The CVersitTlsData 
williamr@2
    41
object is only destroyed when no more parsers refer to it: a count is kept, 
williamr@2
    42
which is incremented every time the constructor is called and decremented each 
williamr@2
    43
time the destructor is called, and the object is only destroyed when the count 
williamr@2
    44
reaches zero.
williamr@2
    45
williamr@2
    46
This class provides an additional major performance improvement 
williamr@2
    47
if you are sequentially constructing and destructing multiple parsers. 
williamr@2
    48
By default, when the count of parsers reaches zero, the thread local 
williamr@2
    49
storage object is destroyed (even if the thread has not finished). However, 
williamr@2
    50
by using the technique described below, the thread local storage object, and therefore 
williamr@2
    51
the unicode utilities object, can be made to persist, significantly reducing 
williamr@2
    52
the overhead of sequentially constructing and destructing parsers.
williamr@2
    53
williamr@2
    54
The constructor needs to be called an extra time before creating any parsers, 
williamr@2
    55
and the destructor needs to be called an extra time once the parsers have 
williamr@2
    56
been destroyed. This has the effect of adding one to the reference count so 
williamr@2
    57
that during all the parser construction and deletion the count never hits 
williamr@2
    58
zero, which would trigger the TLS object's destruction.
williamr@2
    59
williamr@2
    60
This can be implemented as follows:
williamr@2
    61
williamr@2
    62
1. Create a thread local storage data class instance as follows: 
williamr@2
    63
@code
williamr@2
    64
CVersitTlsData* versitTLS = CVersitTlsData::VersitTlsDataL(); 
williamr@2
    65
@endcode
williamr@2
    66
williamr@2
    67
2. Create and delete the parsers. 
williamr@2
    68
williamr@2
    69
3. Delete the Thread Local Storage Data class instance: 
williamr@2
    70
@code
williamr@2
    71
delete versitTLS; 
williamr@2
    72
@endcode 
williamr@2
    73
@publishedAll
williamr@2
    74
@released
williamr@2
    75
*/
williamr@2
    76
	{
williamr@2
    77
	friend class CVersitTimer;
williamr@2
    78
williamr@2
    79
public:
williamr@2
    80
	IMPORT_C static CVersitTlsData& VersitTlsDataL();
williamr@2
    81
	IMPORT_C static void CloseVersitTlsData();
williamr@2
    82
	IMPORT_C void VersitTlsDataClose();
williamr@2
    83
williamr@2
    84
public:
williamr@2
    85
	inline CVersitUnicodeUtils& UnicodeUtils() 
williamr@2
    86
	/** Returns a pointer to the current Unicode utilities object.
williamr@2
    87
	
williamr@2
    88
	@return A pointer to the current Unicode utilities object. */
williamr@2
    89
		{ return *iUnicodeUtils; }
williamr@2
    90
williamr@2
    91
    inline CVersitAdditionalStorage& AdditionalStorage()
williamr@2
    92
	/** Returns a pointer to the additional property storage object.
williamr@2
    93
	
williamr@2
    94
	@return A pointer to the additional property storage. */
williamr@2
    95
        {
williamr@2
    96
        return *iAdditionalStorage;
williamr@2
    97
        }
williamr@2
    98
williamr@2
    99
private:
williamr@2
   100
	static CVersitTlsData* NewL();
williamr@2
   101
	void ConstructL();
williamr@2
   102
	~CVersitTlsData();
williamr@2
   103
williamr@2
   104
private:
williamr@2
   105
	TInt iRefCount;
williamr@2
   106
	CVersitUnicodeUtils* iUnicodeUtils;
williamr@2
   107
    CVersitAdditionalStorage* iAdditionalStorage;
williamr@2
   108
	};
williamr@2
   109
williamr@2
   110
#endif