/*---------------------------------------------------------------------------* Project: Horizon File: osl_MbufSystem.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Rev: 17658 $ *---------------------------------------------------------------------------*/ #ifndef NN_NET_OSL_OSL_MBUF_SYSTEM_H_ #define NN_NET_OSL_OSL_MBUF_SYSTEM_H_ #ifdef __cplusplus #include #include #include #include #include #include #include namespace nn { namespace net { namespace osl { class MbufSystem : public nn::util::Singleton { public: typedef nnnetOslMbufIndex Index; static const s32 MAX_POOL = 16; struct Config { size_t unitSize; s32 count; }; protected: static const u32 MAGIC = 0x9e3fbaba; typedef nn::fnd::InterlockedVariable is32; struct HeaderBlock { u32 magic; u32 poolCount; Config configs[MAX_POOL]; }; public: static const size_t HEADER_SIZE = sizeof(HeaderBlock); void Finalize(void){}; s32 GetPoolCount(void) const; void WaitFree(void); void NotifyFree(void); static size_t GetRequiredMemorySize(const Config pConfigs[], s32 count); static Mbuf* Allocate(size_t size); static Mbuf* TryAllocate(size_t size); static void Free(Mbuf* pMbuf); static MbufIndexed* GetPtrFromIndex(Index index); static Index GetIndexFromPtr(const Mbuf* pMbuf); protected: MbufSystem(); ~MbufSystem(); MbufPool m_Pools[MAX_POOL]; os::SharedMemoryBlock m_SharedMemory; os::Event m_Event; HeaderBlock* m_pHeaderBlock; }; inline s32 MbufSystem::GetPoolCount(void) const { return m_pHeaderBlock->poolCount; } inline void MbufSystem::WaitFree(void) { m_Event.Wait(); } inline void MbufSystem::NotifyFree(void) { m_Event.Signal(); } class MbufServer : public MbufSystem { public: MbufServer(){} ~MbufServer(){} void Initialize(const Config pConfigs[], s32 count); void Finalize(); void GetInfomation(nn::Handle* phSharedMemory, size_t* pSize, nn::Handle* phEvent); }; class MbufClient : public MbufSystem { public: MbufClient(){} ~MbufClient(){} void Initialize(nn::Handle hSharedMemory, size_t size, nn::Handle hEvent); void Finalize(){} }; } } } // namespace nn::net::osl #endif #endif // NN_NET_OSL_OSL_MBUF_SYSTEM_H_