greenplumn CCacheFactory 源码

  • 2022-08-18
  • 浏览 (364)

greenplumn CCacheFactory 代码

文件路径:/src/backend/gporca/libgpos/include/gpos/memory/CCacheFactory.h

//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2011 EMC CORP.
//
//	@filename:
//		CCache.h
//
//	@doc:
//		Definition of cache factory class.
//.
//	@owner:
//
//	@test:
//
//---------------------------------------------------------------------------

#ifndef CCACHEFACTORY_H_
#define CCACHEFACTORY_H_

#include "gpos/base.h"
#include "gpos/memory/CAutoMemoryPool.h"
#include "gpos/memory/CCache.h"

// default initial value of the gclock counter during insertion of an entry
#define CCACHE_GCLOCK_INIT_COUNTER 3

using namespace gpos;

namespace gpos
{
//---------------------------------------------------------------------------
//	@class:
//		CCacheFactory
//
//	@doc:
//		Definition of cache factory;
//
//		This class is responsible of creating cache objects and allocating the
//		memory pools they need
//
//---------------------------------------------------------------------------
class CCacheFactory
{
private:
	// global instance
	static CCacheFactory *m_factory;

	// memory pool allocated to caches
	CMemoryPool *m_mp;

	// private ctor
	CCacheFactory(CMemoryPool *mp);



public:
	CCacheFactory(const CCacheFactory &) = delete;

	// private dtor
	~CCacheFactory()
	{
		GPOS_ASSERT(nullptr == m_factory &&
					"Cache factory has not been shut down");
	}

	// initialize global memory pool
	static GPOS_RESULT Init();

	// destroy global instance
	static void Shutdown();

	// global accessor
	inline static CCacheFactory *
	GetFactory()
	{
		return m_factory;
	}

	// create a cache instance
	template <class T, class K>
	static CCache<T, K> *
	CreateCache(BOOL unique, ULLONG cache_quota,
				typename CCache<T, K>::HashFuncPtr hash_func,
				typename CCache<T, K>::EqualFuncPtr equal_func)
	{
		GPOS_ASSERT(nullptr != GetFactory() &&
					"Cache factory has not been initialized");

		CMemoryPool *mp = GetFactory()->Pmp();
		CCache<T, K> *cache = GPOS_NEW(mp)
			CCache<T, K>(mp, unique, cache_quota, CCACHE_GCLOCK_INIT_COUNTER,
						 hash_func, equal_func);

		return cache;
	}

	CMemoryPool *Pmp() const;

};	// CCacheFactory
}  // namespace gpos


#endif	// CCACHEFACTORY_H_

// EOF

相关信息

greenplumn 源码目录

相关文章

greenplumn CAutoMemoryPool 源码

greenplumn CCache 源码

greenplumn CCacheAccessor 源码

greenplumn CCacheEntry 源码

greenplumn CMemoryPool 源码

greenplumn CMemoryPoolManager 源码

greenplumn CMemoryPoolStatistics 源码

greenplumn CMemoryPoolTracker 源码

greenplumn CMemoryVisitorPrint 源码

greenplumn IMemoryVisitor 源码

0  赞