/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_TaskThread.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace snd { namespace internal { /*---------------------------------------------------------------------------* Name: TaskThread Description: コンストラクタ Arguments: なし Returns: なし *---------------------------------------------------------------------------*/ TaskThread::TaskThread() : m_IsFinished( false ), m_IsCreated( false ) { } TaskThread::~TaskThread() { if ( m_IsCreated ) { Destroy(); } } bool TaskThread::Create( s32 priority, ThreadStack& stack ) { NW_ALIGN4_ASSERT( stack.GetBaseAddress() ); // 多重初期化チェック if ( m_IsCreated ) { Destroy(); } m_IsFinished = false; m_CriticalSection.Initialize(); bool result = m_Thread.TryStart( ThreadFunc, reinterpret_cast(this), stack, priority ).IsSuccess(); if ( result == false ) { return false; } m_IsCreated = true; return true; } /*---------------------------------------------------------------------------* Name: Destroy Description: タスクスレッドを終了する Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ void TaskThread::Destroy() { if ( ! m_IsCreated ) { return; } // サウンドスレッド終了メッセージ送信 m_IsFinished = true; TaskManager::GetInstance().CancelWaitTask(); // スレッドの終了を待つ m_Thread.Join(); m_Thread.Finalize(); m_CriticalSection.Finalize(); m_IsCreated = false; } /*---------------------------------------------------------------------------* Name: TaskThreadFunc Description: サウンドスレッド関数 Arguments: arg - スレッドインスタンス Returns: NULL *---------------------------------------------------------------------------*/ void TaskThread::ThreadFunc( uptr arg ) { TaskThread* taskThread = reinterpret_cast< TaskThread* >( arg ); taskThread->ThreadProc(); } /*---------------------------------------------------------------------------* Name: TaskThreadProc Description: タスクスレッドプロシージャ Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ void TaskThread::ThreadProc() { while ( ! m_IsFinished ) { TaskManager::GetInstance().WaitTask(); if ( m_IsFinished ) { break; } { // NOTE: タスクスレッドのロック。 // // SoundSystem::(Try)LockDataLoadThread 関数で外部からロックされることによって // いったんスレッドが停止します。 // // タスクスレッドはストリームデータのロードや、 // プレイヤーヒープへのデータロードを行いますが、 // 「スリープ中はファイルアクセス禁止」の制約に沿うため、 // このロックが追加されました。 nn::os::CriticalSection::ScopedLock lock( m_CriticalSection ); TaskManager::GetInstance().ExecuteTask(); } DriverCommandManager::GetInstanceForTaskThread().RecvCommandReply(); } } TaskThread& TaskThread::GetInstance() { static TaskThread instance; return instance; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw