1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_SimpleLock.h
4 
5   Copyright (C)2009-2012 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: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_OS_OS_SIMPLELOCK_H_
17 #define NN_OS_OS_SIMPLELOCK_H_
18 
19 #include <nn/os/os_WaitableCounter.h>
20 #include <nn/util/detail/util_ScopedLockImpl.h>
21 #include <nn/util/util_NonCopyable.h>
22 
23 #ifdef __cplusplus
24 
25 namespace nn { namespace os {
26 
27 class SimpleLock : private nn::util::NonCopyable<SimpleLock>
28 {
29 public:
30     class ScopedLock;
31 
32 private:
33     nn::os::WaitableCounter m_Counter;
34 
35 public:
SimpleLock()36     SimpleLock()  {}
~SimpleLock()37     ~SimpleLock() {}
38 
39     void Initialize();
Finalize()40     void Finalize() {}
41 
42     void Lock();
43     bool TryLock();
44     void Unlock();
45 
IsLocked()46     bool IsLocked() const
47     {
48         return (*m_Counter < 0);
49     }
50 
51 private:
52     void LockImpl();
53 };
54 
55 NN_UTIL_DETAIL_DEFINE_SCOPED_LOCK(SimpleLock, Lock(), Unlock());
56 
57 }} // namespace nn::os
58 
59 #endif // __cplusplus
60 
61 
62 #endif  // ifndef NN_OS_OS_SIMPLELOCK_H_
63