greenplumn CCacheFactory 源码
greenplumn CCacheFactory 代码
文件路径:/src/backend/gporca/libgpos/src/memory/CCacheFactory.cpp
//---------------------------------------------------------------------------
// Greenplum Database
// Copyright (C) 2011 EMC Corp.
//
// @filename:
// CCacheFactory.cpp
//
// @doc:
// Function implementation of CCacheFactory
//---------------------------------------------------------------------------
#include "gpos/memory/CCacheFactory.h"
#include "gpos/io/ioutils.h"
#include "gpos/memory/CAutoMemoryPool.h"
#include "gpos/memory/CCache.h"
using namespace gpos;
// global instance of cache factory
CCacheFactory *CCacheFactory::m_factory = nullptr;
//---------------------------------------------------------------------------
// @function:
// CCacheFactory::CCacheFactory
//
// @doc:
// Ctor;
//
//---------------------------------------------------------------------------
CCacheFactory::CCacheFactory(CMemoryPool *mp) : m_mp(mp)
{
}
//---------------------------------------------------------------------------
// @function:
// CCacheFactory::Pmp
//
// @doc:
// Returns a pointer to allocated memory pool
//
//---------------------------------------------------------------------------
CMemoryPool *
CCacheFactory::Pmp() const
{
return m_mp;
}
//---------------------------------------------------------------------------
// @function:
// CCacheFactory::Init
//
// @doc:
// Initializes global instance
//
//---------------------------------------------------------------------------
GPOS_RESULT
CCacheFactory::Init()
{
GPOS_ASSERT(nullptr == GetFactory() &&
"Cache factory was already initialized");
GPOS_RESULT res = GPOS_OK;
// create cache factory memory pool
CMemoryPool *mp =
CMemoryPoolManager::GetMemoryPoolMgr()->CreateMemoryPool();
GPOS_TRY
{
// create cache factory instance
CCacheFactory::m_factory = GPOS_NEW(mp) CCacheFactory(mp);
}
GPOS_CATCH_EX(ex)
{
// destroy memory pool if global instance was not created
CMemoryPoolManager::GetMemoryPoolMgr()->Destroy(mp);
CCacheFactory::m_factory = nullptr;
if (GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiOOM))
{
res = GPOS_OOM;
}
else
{
res = GPOS_FAILED;
}
}
GPOS_CATCH_END;
return res;
}
//---------------------------------------------------------------------------
// @function:
// CCacheFactory::Shutdown
//
// @doc:
// Cleans up allocated memory pool
//
//---------------------------------------------------------------------------
void
CCacheFactory::Shutdown()
{
CCacheFactory *factory = CCacheFactory::GetFactory();
GPOS_ASSERT(nullptr != factory && "Cache factory has not been initialized");
CMemoryPool *mp = factory->m_mp;
// destroy cache factory
CCacheFactory::m_factory = nullptr;
GPOS_DELETE(factory);
// release allocated memory pool
CMemoryPoolManager::GetMemoryPoolMgr()->Destroy(mp);
}
// EOF
相关信息
相关文章
greenplumn CMemoryPoolManager 源码
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦