Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 _LIT(KThreadRandom, "threadrandom.cpp");
23 EXPORT_C void SetThreadRandomL(CRandom* aRNG)
25 User::LeaveIfError(Dll::SetTls(aRNG));
28 EXPORT_C void SetThreadRandomLC(CRandom* aRNG)
30 CleanupStack::PushL(aRNG);
31 SetThreadRandomL(aRNG);
32 //This pop before the push isn't a problem as the PushL can't fail.
33 //We just did a push before this and thus there is enough room on the
34 //cleanupstack such that OOM is not possible.
35 CleanupStack::Pop(aRNG);
36 CleanupStack::PushL(TCleanupItem(&DeleteThreadRandom, Dll::Tls()));
39 void DeleteThreadRandom(TAny* aPtr)
41 CRandom* random = reinterpret_cast<CRandom*>(aPtr);
43 TInt result = Dll::SetTls(0);
44 __ASSERT_ALWAYS(result == 0, User::Panic(KThreadRandom, 1));
47 EXPORT_C void DestroyThreadRandom(void)
49 delete (CRandom*)(Dll::Tls());
50 TInt result = Dll::SetTls(0);
51 __ASSERT_ALWAYS(result == 0, User::Panic(KThreadRandom, 1));
54 EXPORT_C void GenerateRandomBytesL(TDes8& aDest)
56 TAny* tls = Dll::Tls();
59 ((CRandom*)tls)->GenerateBytesL(aDest);
63 TRandom::RandomL(aDest);