1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_TaskThread.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  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   $Revision: 29726 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_SND_TASK_THREAD_H_
17 #define NW_SND_TASK_THREAD_H_
18 
19 #include <nw/snd/snd_ThreadStack.h>
20 
21 namespace nw {
22 namespace snd {
23 namespace internal {
24 
25 class TaskThread
26 {
27 public:
28     TaskThread();
29     ~TaskThread();
30 
31     bool Create( s32 priority, ThreadStack& stack );
32     void Destroy();
33 
IsCreated()34     bool IsCreated() const { return m_IsCreated != 0; }
35 
SetPriority(s32 priority)36     void SetPriority( s32 priority )
37     {
38         m_Thread.ChangePriority( priority );
39     }
40 
TryLock()41     bool TryLock()
42     {
43         return m_CriticalSection.TryEnter();
44     }
Lock()45     void Lock()
46     {
47         m_CriticalSection.Enter();
48     }
Unlock()49     void Unlock()
50     {
51         m_CriticalSection.Leave();
52     }
53 
54 private:
55     void ThreadProc();
56     static void ThreadFunc( uptr arg );
57 
58     nn::os::Thread  m_Thread;
59     mutable nn::os::CriticalSection m_CriticalSection;
60 
61     volatile bool m_IsFinished;
62     bool m_IsCreated;
63 };
64 
65 } // namespace nw::snd::internal
66 } // namespace nw::snd
67 } // namespace nw
68 
69 
70 #endif /* NW_SND_TASK_THREAD_H_ */
71 
72