#include "test/librados_test_stub/TestMemRadosClient.h"
#include "objclass/objclass.h"
#include <boost/bind.hpp>
+#include <boost/shared_ptr.hpp>
#include <deque>
#include <list>
#include <vector>
#define dout_subsys ceph_subsys_rados
+namespace {
+
+static void DeallocateRadosClient(librados::TestRadosClient* client)
+{
+ client->put();
+}
+
+} // anonymous namespace
+
+
static librados::TestClassHandler *get_class_handler() {
- static librados::TestClassHandler *s_class_handler = NULL;
- if (s_class_handler == NULL) {
- s_class_handler = new librados::TestClassHandler();
+ static boost::shared_ptr<librados::TestClassHandler> s_class_handler;
+ if (!s_class_handler) {
+ s_class_handler.reset(new librados::TestClassHandler());
s_class_handler->open_all_classes();
}
- return s_class_handler;
+ return s_class_handler.get();
}
static librados::TestRadosClient *get_rados_client() {
// TODO: use factory to allow tests to swap out impl
- static librados::TestRadosClient *s_rados_client = NULL;
- if (s_rados_client == NULL) {
+ static boost::shared_ptr<librados::TestRadosClient> s_rados_client;
+ if (!s_rados_client) {
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
cct->_conf->parse_env();
cct->_conf->apply_changes(NULL);
- g_ceph_context = cct;
- s_rados_client = new librados::TestMemRadosClient(cct);
+ s_rados_client.reset(new librados::TestMemRadosClient(cct),
+ &DeallocateRadosClient);
cct->put();
}
s_rados_client->get();
- return s_rados_client;
+ return s_rados_client.get();
}
static void do_out_buffer(bufferlist& outbl, char **outbuf, size_t *outbuflen) {
TestWatchNotify::TestWatchNotify(CephContext *cct)
: m_cct(cct), m_finisher(new Finisher(cct)), m_handle(), m_notify_id(),
m_file_watcher_lock("librados::TestWatchNotify::m_file_watcher_lock") {
+ m_cct->get();
m_finisher->start();
}
TestWatchNotify::~TestWatchNotify() {
m_finisher->stop();
delete m_finisher;
+ m_cct->put();
}
TestWatchNotify::NotifyHandle::NotifyHandle()