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 #include "randomshim.h"
23 _LIT(KThreadRandom, "threadrandom.cpp");
25 EXPORT_C void SetThreadRandomL(CRandom* aRNG)
27 User::LeaveIfError(Dll::SetTls(aRNG));
30 EXPORT_C void SetThreadRandomLC(CRandom* aRNG)
32 CleanupStack::PushL(aRNG);
33 SetThreadRandomL(aRNG);
34 //This pop before the push isn't a problem as the PushL can't fail.
35 //We just did a push before this and thus there is enough room on the
36 //cleanupstack such that OOM is not possible.
37 CleanupStack::Pop(aRNG);
38 CleanupStack::PushL(TCleanupItem(&DeleteThreadRandom, Dll::Tls()));
41 void DeleteThreadRandom(TAny* aPtr)
43 CRandom* random = reinterpret_cast<CRandom*>(aPtr);
45 TInt result = Dll::SetTls(0);
46 __ASSERT_ALWAYS(result == 0, User::Panic(KThreadRandom, 1));
49 EXPORT_C void DestroyThreadRandom(void)
51 delete (CRandom*)(Dll::Tls());
52 TInt result = Dll::SetTls(0);
53 __ASSERT_ALWAYS(result == 0, User::Panic(KThreadRandom, 1));
56 EXPORT_C void GenerateRandomBytesL(TDes8& aDest)
58 TAny* tls = Dll::Tls();
61 ((CRandom*)tls)->GenerateBytesL(aDest);
65 TRandomShim::RandomL(aDest);