1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_TaskManager.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_SND_TASK_MANAGER_H_ 19 #define NW_SND_TASK_MANAGER_H_ 20 21 #include <nw/snd/snd_Task.h> 22 #include <nw/snd/snd_Util.h> 23 #include <nw/ut/ut_LinkList.h> 24 #include <nn/os.h> 25 26 namespace nw { 27 namespace snd { 28 namespace internal { 29 30 class TaskManager 31 { 32 public: 33 enum TaskPriority 34 { 35 PRIORITY_LOW, 36 PRIORITY_MIDDLE, 37 PRIORITY_HIGH 38 }; 39 40 static TaskManager& GetInstance(); 41 42 void Initialize(); 43 void Finalize(); 44 45 void ExecuteTask(); 46 void AppendTask( Task* task, TaskPriority priority ); 47 void CancelTask( Task* task ); 48 void CancelTaskById( u32 id ); 49 void CancelAllTask(); 50 51 void WaitTask(); 52 void CancelWaitTask(); 53 54 private: 55 static const u32 PRIORITY_NUM = PRIORITY_HIGH - PRIORITY_LOW + 1; 56 static const u32 THREAD_MESSAGE_BUFSIZE = 32; // 必要に応じて要調整 57 58 enum Message 59 { 60 MESSAGE_APPEND 61 }; 62 63 typedef ut::LinkList< Task, offsetof(Task,m_TaskLink)> TaskList; 64 65 TaskManager(); 66 Task* PopTask(); 67 bool RemoveTask(Task* task); 68 void RemoveTaskById(u32 id); 69 70 Task* GetNextTask(); 71 Task* GetNextTask( TaskPriority priority, bool doRemove ); 72 73 TaskList m_TaskList[ PRIORITY_NUM ]; 74 75 Task* volatile m_pCurrentTask; 76 77 volatile bool m_IsWaitTaskCancel; 78 79 nn::os::CriticalSection m_CriticalSection; 80 nn::os::BlockingQueue m_BlockingQueue; 81 uptr m_MsgBuffer[ THREAD_MESSAGE_BUFSIZE ]; 82 }; 83 84 85 } // namespace nw::snd::internal 86 } // namespace nw::snd 87 } // namespace nw 88 89 90 #endif /* NW_SND_TASK_MANAGER_H_ */ 91 92