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