1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_WaitableCounter.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: 12372 $
14  *---------------------------------------------------------------------------*/
15 
16 
17 #include <nn/os/os_WaitableCounter.h>
18 #include <nn/assert.h>
19 
20 
21 namespace nn { namespace os {
22 
23     // 明示的に INVALID_HANDLE_VALUE で初期化すると
24     // static_initializer での初期化になるので bss クリアに頼る
25     nnHandle WaitableCounter::s_Handle = {0};
26 
Initialize()27     void WaitableCounter::Initialize()
28     {
29         if( s_Handle.value == INVALID_HANDLE_VALUE.value )
30         {
31             Handle h;
32             Result ret = nn::svc::CreateAddressArbiter(&h);
33             NN_TASSERT_( ret.IsSuccess() );
34 
35             if( ret.IsSuccess() )
36             {
37                 s_Handle = h;
38             }
39         }
40     }
41 
Finalize()42     void WaitableCounter::Finalize()
43     {
44         if( s_Handle.value != INVALID_HANDLE_VALUE.value )
45         {
46             Result ret = nn::svc::CloseHandle(s_Handle);
47             NN_TASSERT_( ret.IsSuccess() );
48 
49             if( ret.IsSuccess() )
50             {
51                 s_Handle.value = INVALID_HANDLE_VALUE.value;
52             }
53         }
54     }
55 
56 }}
57 
58