/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_DriverCommandManager.h 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 $ *---------------------------------------------------------------------------*/ #ifndef NW_SND_DRIVER_COMMAND_MANAGER_H_ #define NW_SND_DRIVER_COMMAND_MANAGER_H_ #include #include #include namespace nw { namespace snd { namespace internal { class DriverCommandManager { public: static DriverCommandManager& GetInstance(); static DriverCommandManager& GetInstanceForTaskThread(); void Initialize( void* commandBuffer, u32 commandBufferSize ); void Finalize(); template< typename Command > Command* AllocCommand(); u32 GetAllocatableCommandSize() const; u32 PushCommand( DriverCommand* command ); void RecvCommandReply(); u32 FlushCommand( bool forceFlag ); void WaitCommandReply( u32 tag ); bool IsFinishCommand( u32 tag ) const; void ProcessCommand(); private: static const int COMMAND_QUEUE_SIZE = 32; DriverCommandManager(); void* AllocMemory( u32 count ); void* TryAllocMemory( u32 count ); void FinalizeCommandList( DriverCommand* command ); #ifdef NW_SND_CONFIG_USE_INTERCORE_CRITICALSECTION typedef nn::os::InterCoreBlockingQueue CommandQueue; #else typedef nn::os::BlockingQueue CommandQueue; #endif CommandQueue m_SendCommandQueue; uptr m_SendCommandQueueBuffer[ COMMAND_QUEUE_SIZE ]; CommandQueue m_RecvCommandQueue; uptr m_RecvCommandQueueBuffer[ COMMAND_QUEUE_SIZE ]; DriverCommand* m_CommandListBegin; DriverCommand* m_CommandListEnd; u32 m_CommandTag; u32 m_FinishCommandTag; u32* m_CommandMemoryArea; u32 m_CommandMemoryAreaSize; u32 m_CommandMemoryAreaBegin; u32 m_CommandMemoryAreaEnd; // m_CommandMemoryAreaBegin == m_CommandMemoryAreaBegin の時、 // エリアサイズがゼロなのか、最大なのかを判定するフラグ bool m_CommandMemoryAreaZeroFlag; }; template< typename Command > Command* DriverCommandManager::AllocCommand() { u32 commandAreaCount = ( sizeof(Command) + sizeof(m_CommandMemoryArea[0]) - 1 ) / sizeof(m_CommandMemoryArea[0]); Command* command = reinterpret_cast( AllocMemory( commandAreaCount ) ); command->memory_next = m_CommandMemoryAreaBegin; return command; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw #endif /* NW_SND_DRIVER_COMMAND_MANAGER_H_ */