/*---------------------------------------------------------------------------* Project: Horizon File: os_InterCoreLightSemaphore.cpp Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 33107 $ *---------------------------------------------------------------------------*/ #include //--------------------------------------------------------------------------- namespace nn { namespace os { s32 InterCoreLightSemaphore::Release(s32 releaseCount /*= 1*/) { NN_MIN_TASSERT_( releaseCount, 1 ); #if NN_PLATFORM_HAS_16BIT_LL_SC LimitedAdd updater; updater.max = m_Max; updater.value = releaseCount; m_Counter->AtomicUpdateConditional(updater); const s32 beforeUpdate = updater.beforeUpdate; #else const s32 beforeUpdate = m_Counter->operator++(0); #endif DataSynchronizationBarrier(); // If the counter before addition is zero, the thread for the value to be added is woken up. if( (beforeUpdate <= 0) || (m_NumWaiting > 0) ) { m_Counter.Signal(releaseCount); } return beforeUpdate; } } } using namespace nn; // C Function Definitions #include using namespace nn::os; extern "C" { void nnosInterCoreLightSemaphoreInitialize(nnosInterCoreLightSemaphore* p, s32 initialCount, s32 maxCount) { new (p) InterCoreLightSemaphore(); InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); pInterCoreLightSemaphore->Initialize(initialCount, maxCount); } #if NN_PLATFORM_HAS_16BIT_LL_SC s32 nnosInterCoreLightSemaphoreGetMax(nnosInterCoreLightSemaphore* p) { InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); return pInterCoreLightSemaphore->GetMax(); } #endif s32 nnosInterCoreLightSemaphoreGetCount(nnosInterCoreLightSemaphore* p) { InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); return pInterCoreLightSemaphore->GetCount(); } s32 nnosInterCoreLightSemaphoreRelease(nnosInterCoreLightSemaphore* p, s32 releaseCount) { InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); return pInterCoreLightSemaphore->Release(releaseCount); } void nnosInterCoreLightSemaphoreAcquire(nnosInterCoreLightSemaphore* p) { InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); pInterCoreLightSemaphore->Acquire(); } bool nnosInterCoreLightSemaphoreTryAcquire(nnosInterCoreLightSemaphore* p) { InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); return pInterCoreLightSemaphore->TryAcquire(); } void nnosInterCoreLightSemaphoreFinalize(nnosInterCoreLightSemaphore* p) { InterCoreLightSemaphore* pInterCoreLightSemaphore = reinterpret_cast(p); pInterCoreLightSemaphore->~InterCoreLightSemaphore(); } } // extern "C"