os/kernelhwsrv/kernel/eka/euser/epoc/arm/uc_data.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\euser\epoc\arm\uc_data.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "us_data.h"
sl@0
    19
sl@0
    20
#ifdef __USERSIDE_THREAD_DATA__
sl@0
    21
sl@0
    22
TAny* TLocalThreadData::DllTls(TInt aHandle, TInt aDllUid)
sl@0
    23
	{
sl@0
    24
	if (!iTlsHeap)
sl@0
    25
		return NULL;
sl@0
    26
	STls tls;
sl@0
    27
	tls.iHandle=aHandle;
sl@0
    28
	TInt r=iTls.FindInSignedKeyOrder(tls);
sl@0
    29
	if (r>=0 && iTls[r].iDllUid==aDllUid)
sl@0
    30
		return iTls[r].iPtr;
sl@0
    31
	return NULL;
sl@0
    32
	}
sl@0
    33
sl@0
    34
TInt TLocalThreadData::DllSetTls(TInt aHandle, TInt aDllUid, TAny* aPtr)
sl@0
    35
	{
sl@0
    36
	if (!iTlsHeap)
sl@0
    37
		{
sl@0
    38
		new (&iTls) RArray<STls>(KTlsArrayGranularity, _FOFF(STls,iHandle));
sl@0
    39
		iHeap->Open();
sl@0
    40
		iTlsHeap = iHeap;
sl@0
    41
		}
sl@0
    42
	
sl@0
    43
	STls tls;
sl@0
    44
	tls.iHandle = aHandle;
sl@0
    45
	tls.iDllUid = aDllUid;
sl@0
    46
	tls.iPtr = aPtr;
sl@0
    47
	TInt i;
sl@0
    48
	TInt r=iTls.FindInSignedKeyOrder(tls,i);
sl@0
    49
	if (r==KErrNone)
sl@0
    50
		iTls[i] = tls;
sl@0
    51
	else
sl@0
    52
		{
sl@0
    53
		RAllocator* currentHeap = iHeap;
sl@0
    54
		iHeap = iTlsHeap;
sl@0
    55
		r = iTls.Insert(tls,i);
sl@0
    56
		iHeap = currentHeap;
sl@0
    57
		}
sl@0
    58
	return r;
sl@0
    59
	}
sl@0
    60
sl@0
    61
void TLocalThreadData::DllFreeTls(TInt aHandle)
sl@0
    62
	{
sl@0
    63
	if (!iTlsHeap)
sl@0
    64
		return;
sl@0
    65
	
sl@0
    66
	STls tls;
sl@0
    67
	tls.iHandle=aHandle;
sl@0
    68
	TInt r=iTls.FindInSignedKeyOrder(tls);
sl@0
    69
	if (r>=0)
sl@0
    70
		{
sl@0
    71
		RAllocator* currentHeap = iHeap;
sl@0
    72
		iHeap = iTlsHeap;
sl@0
    73
		iTls.Remove(r);
sl@0
    74
		iTls.Compress();
sl@0
    75
		iHeap = currentHeap;
sl@0
    76
		}
sl@0
    77
	}
sl@0
    78
sl@0
    79
void TLocalThreadData::Close()
sl@0
    80
	{
sl@0
    81
	RAllocator* currentHeap = iHeap;
sl@0
    82
	RAllocator* tlsHeap = iTlsHeap;
sl@0
    83
	if (tlsHeap)
sl@0
    84
		{
sl@0
    85
		iHeap = tlsHeap;
sl@0
    86
		iTls.Close();
sl@0
    87
		iHeap = currentHeap;
sl@0
    88
		iTlsHeap = NULL;
sl@0
    89
		tlsHeap->Close();
sl@0
    90
		}
sl@0
    91
	}
sl@0
    92
sl@0
    93
#endif