os/kernelhwsrv/kernel/eka/memmodel/epoc/flexible/mmu/mcleanup.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 //
    15 
    16 #include <plat_priv.h>
    17 #include "mm.h"
    18 #include "mmu.h"
    19 
    20 #include "mcleanup.h"
    21 
    22 
    23 //
    24 // TMemoryCleanup
    25 //
    26 
    27 static TDfc CleanupDfc(TMemoryCleanup::Cleanup, NULL, 2);
    28 
    29 static TMemoryCleanup* CleanupList = 0;
    30 
    31 #ifdef __SMP__
    32 static TSpinLock CleanupLock(TSpinLock::EOrderEventHandlerList);
    33 #endif
    34 
    35 void TMemoryCleanup::Init2()
    36 	{
    37 	CleanupDfc.SetDfcQ(K::SvMsgQ);
    38 	}
    39 
    40 
    41 void TMemoryCleanup::Add(TMemoryCleanupCallback aCallback, TAny* aArg)
    42 	{
    43 	__SPIN_LOCK_IRQ(CleanupLock);
    44 	if(iCallback)
    45 		{
    46 		// already queued...
    47 		__NK_ASSERT_DEBUG(iCallback==aCallback);
    48 		__SPIN_UNLOCK_IRQ(CleanupLock);
    49 		}
    50 	else
    51 		{
    52 		iCallback = aCallback;
    53 		iArg = aArg;
    54 		iNext = CleanupList;
    55 		CleanupList = this;
    56 		__SPIN_UNLOCK_IRQ(CleanupLock);
    57 		CleanupDfc.Enque();
    58 		}
    59 	}
    60 
    61 
    62 void TMemoryCleanup::Cleanup(TAny* /*aDummy*/)
    63 	{
    64 	for(;;)
    65 		{
    66 		__SPIN_LOCK_IRQ(CleanupLock);
    67 		TMemoryCleanup* c = CleanupList;
    68 		if(!c)
    69 			{
    70 			__SPIN_UNLOCK_IRQ(CleanupLock);
    71 			return;
    72 			}
    73 
    74 		CleanupList = c->iNext;
    75 		TMemoryCleanupCallback fn = c->iCallback;
    76 		TAny* arg = c->iArg;
    77 		c->iCallback = 0;
    78 		__SPIN_UNLOCK_IRQ(CleanupLock);
    79 		(*fn)(arg);
    80 		}
    81 	}