1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_TaskManager.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: 21442 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_SND_TASK_MANAGER_H_ 17 #define NW_SND_TASK_MANAGER_H_ 18 19 #include <nw/snd/snd_Task.h> 20 #include <nw/snd/snd_Util.h> 21 #include <nw/ut/ut_LinkList.h> 22 #include <nn/os.h> 23 24 namespace nw { 25 namespace snd { 26 namespace internal { 27 28 class TaskManager 29 { 30 public: 31 enum TaskPriority 32 { 33 PRIORITY_LOW, 34 PRIORITY_MIDDLE, 35 PRIORITY_HIGH 36 }; 37 38 static TaskManager& GetInstance(); 39 40 void Initialize(); 41 void Finalize(); 42 43 void ExecuteTask(); 44 void AppendTask( Task* task, TaskPriority priority ); 45 void CancelTask( Task* task ); 46 void CancelTaskById( u32 id ); 47 void CancelAllTask(); 48 49 void WaitTask(); 50 void CancelWaitTask(); 51 52 private: 53 static const u32 PRIORITY_NUM = PRIORITY_HIGH - PRIORITY_LOW + 1; 54 static const u32 THREAD_MESSAGE_BUFSIZE = 32; // 必要に応じて要調整 55 56 enum Message 57 { 58 MESSAGE_APPEND 59 }; 60 61 typedef ut::LinkList< Task, offsetof(Task,m_TaskLink)> TaskList; 62 63 TaskManager(); 64 Task* PopTask(); 65 bool RemoveTask(Task* task); 66 void RemoveTaskById(u32 id); 67 68 Task* GetNextTask(); 69 Task* GetNextTask( TaskPriority priority, bool doRemove ); 70 71 TaskList m_TaskList[ PRIORITY_NUM ]; 72 73 Task* volatile m_pCurrentTask; 74 75 volatile bool m_IsWaitTaskCancel; 76 77 nn::os::CriticalSection m_CriticalSection; 78 nn::os::BlockingQueue m_BlockingQueue; 79 uptr m_MsgBuffer[ THREAD_MESSAGE_BUFSIZE ]; 80 }; 81 82 83 } // namespace nw::snd::internal 84 } // namespace nw::snd 85 } // namespace nw 86 87 88 #endif /* NW_SND_TASK_MANAGER_H_ */ 89 90