Cache: Use auto_ptr in storage_inmemory
This commit is contained in:
parent
16fad9c2cd
commit
9519be5e60
@ -15,6 +15,7 @@
|
||||
#include "inmemorystoragemt.hh"
|
||||
|
||||
using maxscale::SpinLockGuard;
|
||||
using std::auto_ptr;
|
||||
|
||||
InMemoryStorageMT::InMemoryStorageMT(const std::string& name, uint32_t ttl)
|
||||
: InMemoryStorage(name, ttl)
|
||||
@ -27,11 +28,11 @@ InMemoryStorageMT::~InMemoryStorageMT()
|
||||
}
|
||||
|
||||
// static
|
||||
InMemoryStorageMT* InMemoryStorageMT::create(const std::string& name,
|
||||
uint32_t ttl,
|
||||
int argc, char* argv[])
|
||||
auto_ptr<InMemoryStorageMT> InMemoryStorageMT::create(const std::string& name,
|
||||
uint32_t ttl,
|
||||
int argc, char* argv[])
|
||||
{
|
||||
return new InMemoryStorageMT(name, ttl);
|
||||
return auto_ptr<InMemoryStorageMT>(new InMemoryStorageMT(name, ttl));
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorageMT::get_info(uint32_t what, json_t** ppInfo) const
|
||||
|
@ -21,7 +21,9 @@ class InMemoryStorageMT : public InMemoryStorage
|
||||
public:
|
||||
~InMemoryStorageMT();
|
||||
|
||||
static InMemoryStorageMT* create(const std::string& name, uint32_t ttl, int argc, char* argv[]);
|
||||
typedef std::auto_ptr<InMemoryStorageMT> SInMemoryStorageMT;
|
||||
|
||||
static SInMemoryStorageMT create(const std::string& name, uint32_t ttl, int argc, char* argv[]);
|
||||
|
||||
cache_result_t get_info(uint32_t what, json_t** ppInfo) const;
|
||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppresult);
|
||||
|
@ -14,6 +14,8 @@
|
||||
#define MXS_MODULE_NAME "storage_inmemory"
|
||||
#include "inmemorystoragest.hh"
|
||||
|
||||
using std::auto_ptr;
|
||||
|
||||
InMemoryStorageST::InMemoryStorageST(const std::string& name, uint32_t ttl)
|
||||
: InMemoryStorage(name, ttl)
|
||||
{
|
||||
@ -24,11 +26,11 @@ InMemoryStorageST::~InMemoryStorageST()
|
||||
}
|
||||
|
||||
// static
|
||||
InMemoryStorageST* InMemoryStorageST::create(const std::string& name,
|
||||
uint32_t ttl,
|
||||
int argc, char* argv[])
|
||||
auto_ptr<InMemoryStorageST> InMemoryStorageST::create(const std::string& name,
|
||||
uint32_t ttl,
|
||||
int argc, char* argv[])
|
||||
{
|
||||
return new InMemoryStorageST(name, ttl);
|
||||
return auto_ptr<InMemoryStorageST>(new InMemoryStorageST(name, ttl));
|
||||
}
|
||||
|
||||
cache_result_t InMemoryStorageST::get_info(uint32_t what, json_t** ppinfo) const
|
||||
|
@ -20,7 +20,9 @@ class InMemoryStorageST : public InMemoryStorage
|
||||
public:
|
||||
~InMemoryStorageST();
|
||||
|
||||
static InMemoryStorageST* create(const std::string& name, uint32_t ttl, int argc, char* argv[]);
|
||||
typedef std::auto_ptr<InMemoryStorageST> SInMemoryStorageST;
|
||||
|
||||
static SInMemoryStorageST create(const std::string& name, uint32_t ttl, int argc, char* argv[]);
|
||||
|
||||
cache_result_t get_info(uint32_t what, json_t** ppinfo) const;
|
||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppresult);
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "inmemorystoragest.hh"
|
||||
#include "inmemorystoragemt.hh"
|
||||
|
||||
using std::auto_ptr;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@ -50,33 +52,33 @@ CACHE_STORAGE* createInstance(cache_thread_model_t model,
|
||||
"does not enforce such a limit.", (unsigned long)max_size);
|
||||
}
|
||||
|
||||
InMemoryStorage* pStorage = NULL;
|
||||
auto_ptr<InMemoryStorage> sStorage;
|
||||
|
||||
switch (model)
|
||||
{
|
||||
case CACHE_THREAD_MODEL_ST:
|
||||
MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv));
|
||||
MXS_EXCEPTION_GUARD(sStorage = InMemoryStorageST::create(zname, ttl, argc, argv));
|
||||
break;
|
||||
|
||||
default:
|
||||
ss_dassert(!true);
|
||||
MXS_ERROR("Unknown thread model %d, creating multi-thread aware storage.", (int)model);
|
||||
case CACHE_THREAD_MODEL_MT:
|
||||
MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv));
|
||||
MXS_EXCEPTION_GUARD(sStorage = InMemoryStorageST::create(zname, ttl, argc, argv));
|
||||
break;
|
||||
}
|
||||
|
||||
if (pStorage)
|
||||
if (sStorage.get())
|
||||
{
|
||||
MXS_NOTICE("Storage module created.");
|
||||
}
|
||||
|
||||
return reinterpret_cast<CACHE_STORAGE*>(pStorage);
|
||||
return reinterpret_cast<CACHE_STORAGE*>(sStorage.release());
|
||||
}
|
||||
|
||||
void freeInstance(CACHE_STORAGE* pinstance)
|
||||
{
|
||||
delete reinterpret_cast<InMemoryStorage*>(pinstance);
|
||||
MXS_EXCEPTION_GUARD(delete reinterpret_cast<InMemoryStorage*>(pinstance));
|
||||
}
|
||||
|
||||
cache_result_t getInfo(CACHE_STORAGE* pStorage,
|
||||
|
Loading…
x
Reference in New Issue
Block a user