public:
IoCtx();
static void from_rados_ioctx_t(rados_ioctx_t p, IoCtx &pool);
+ IoCtx(const IoCtx& rhs);
+ IoCtx& operator=(const IoCtx& rhs);
// Close our pool handle
~IoCtx();
friend class Rados; // Only Rados can use our private constructor to create IoCtxes.
- /* We don't allow assignment or copying */
- IoCtx(const IoCtx& rhs);
- const IoCtx& operator=(const IoCtx& rhs);
+ int ref_cnt;
IoCtxImpl *io_ctx_impl;
};
///////////////////////////// RadosClient //////////////////////////////
struct librados::IoCtxImpl {
+ int ref_cnt;
RadosClient *client;
int poolid;
string pool_name;
uint32_t notify_timeout;
IoCtxImpl(RadosClient *c, int pid, const char *pool_name_, snapid_t s = CEPH_NOSNAP) :
- client(c), poolid(pid), pool_name(pool_name_), snap_seq(s), assert_ver(0),
- notify_timeout(g_conf.client_notify_timeout) {}
+ ref_cnt(0), client(c), poolid(pid), pool_name(pool_name_), snap_seq(s),
+ assert_ver(0), notify_timeout(g_conf.client_notify_timeout) {}
void set_snap_read(snapid_t s) {
if (!s)
IoCtxImpl *io_ctx_impl = (IoCtxImpl*)p;
io.io_ctx_impl = io_ctx_impl;
+ io_ctx_impl->ref_cnt++;
+}
+
+librados::IoCtx::
+IoCtx(const IoCtx& rhs)
+{
+ io_ctx_impl = rhs.io_ctx_impl;
+ io_ctx_impl->ref_cnt++;
+}
+
+librados::IoCtx& librados::IoCtx::
+operator=(const IoCtx& rhs)
+{
+ io_ctx_impl = rhs.io_ctx_impl;
+ io_ctx_impl->ref_cnt++;
+ return *this;
}
librados::IoCtx::
~IoCtx()
{
- delete io_ctx_impl;
+ io_ctx_impl->ref_cnt--;
+ if (io_ctx_impl->ref_cnt <= 0)
+ delete io_ctx_impl;
io_ctx_impl = 0;
}
if (!ctx)
return -ENOMEM;
*io = ctx;
+ ctx->ref_cnt++;
return 0;
}
return poolid;
extern "C" void rados_ioctx_destroy(rados_ioctx_t io)
{
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
- delete ctx;
+ ctx->ref_cnt--;
+ if (ctx->ref_cnt <= 0)
+ delete ctx;
}
extern "C" int rados_ioctx_stat(rados_ioctx_t io, struct rados_ioctx_stat_t *stats)