1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: os_LightSemaphore.cpp
4
5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 16480 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn/os/os_LightSemaphore.h>
17
18 //---------------------------------------------------------------------------
19
20 namespace nn {
21 namespace os {
22
Release(s32 releaseCount)23 s32 LightSemaphore::Release(s32 releaseCount /*= 1*/)
24 {
25 NN_MIN_TASSERT_( releaseCount, 1 );
26
27 LimitedAdd updater;
28 updater.max = m_Max;
29 updater.value = releaseCount;
30
31 m_Counter->AtomicUpdateConditional(updater);
32
33 // 加算前のカウンタが 0 であれば、加算した値分のスレッドを起床します。
34 if( updater.beforeUpdate <= 0 )
35 {
36 m_Counter.Signal(releaseCount);
37 }
38
39 return updater.beforeUpdate;
40 }
41
42 }
43 }
44
45 using namespace nn;
46
47
48 // C 関数の定義
49
50 #include <new>
51
52 using namespace nn::os;
53
54 extern "C" {
55
nnosLightSemaphoreInitialize(nnosLightSemaphore * p,s32 initialCount,s32 maxCount)56 void nnosLightSemaphoreInitialize(nnosLightSemaphore* p, s32 initialCount, s32 maxCount)
57 {
58 new (p) LightSemaphore();
59 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
60 pLightSemaphore->Initialize(initialCount, maxCount);
61 }
62
nnosLightSemaphoreGetMax(nnosLightSemaphore * p)63 s32 nnosLightSemaphoreGetMax(nnosLightSemaphore* p)
64 {
65 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
66 return pLightSemaphore->GetMax();
67 }
68
nnosLightSemaphoreGetCount(nnosLightSemaphore * p)69 s32 nnosLightSemaphoreGetCount(nnosLightSemaphore* p)
70 {
71 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
72 return pLightSemaphore->GetCount();
73 }
74
nnosLightSemaphoreRelease(nnosLightSemaphore * p,s32 releaseCount)75 s32 nnosLightSemaphoreRelease(nnosLightSemaphore* p, s32 releaseCount)
76 {
77 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
78 return pLightSemaphore->Release(releaseCount);
79 }
80
nnosLightSemaphoreAcquire(nnosLightSemaphore * p)81 void nnosLightSemaphoreAcquire(nnosLightSemaphore* p)
82 {
83 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
84 pLightSemaphore->Acquire();
85 }
86
nnosLightSemaphoreTryAcquire(nnosLightSemaphore * p)87 bool nnosLightSemaphoreTryAcquire(nnosLightSemaphore* p)
88 {
89 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
90 return pLightSemaphore->TryAcquire();
91 }
92
nnosLightSemaphoreFinalize(nnosLightSemaphore * p)93 void nnosLightSemaphoreFinalize(nnosLightSemaphore* p)
94 {
95 LightSemaphore* pLightSemaphore = reinterpret_cast<LightSemaphore*>(p);
96 pLightSemaphore->~LightSemaphore();
97 }
98
99 } // extern "C"
100