_crypto_aes(NULL)
{
ceph_spin_init(&_service_thread_lock);
+ ceph_spin_init(&_associated_objs_lock);
_log = new ceph::log::Log(&_conf->subsys);
_log->start();
{
join_service_thread();
+ for (map<string, AssociatedSingletonObject*>::iterator it = _associated_objs.begin();
+ it != _associated_objs.end(); it++)
+ delete it->second;
+
if (_conf->lockdep) {
lockdep_unregister_ceph_context(this);
}
delete _conf;
ceph_spin_destroy(&_service_thread_lock);
+ ceph_spin_destroy(&_associated_objs_lock);
delete _crypto_none;
delete _crypto_aes;
#include <iostream>
#include <stdint.h>
+#include <string>
+using namespace std;
#include "include/buffer.h"
#include "include/atomic.h"
~CephContext();
atomic_t nref;
public:
+ class AssociatedSingletonObject {
+ public:
+ virtual ~AssociatedSingletonObject() {}
+ };
CephContext *get() {
nref.inc();
return this;
void do_command(std::string command, cmdmap_t& cmdmap, std::string format,
bufferlist *out);
+ template<typename T>
+ void lookup_or_create_singleton_object(T*& p, const string &name) {
+ ceph_spin_lock(&_associated_objs_lock);
+ if (!_associated_objs.count(name)) {
+ p = new T(this);
+ _associated_objs[name] = reinterpret_cast<AssociatedSingletonObject*>(p);
+ } else {
+ p = reinterpret_cast<T*>(_associated_objs[name]);
+ }
+ ceph_spin_unlock(&_associated_objs_lock);
+ }
/**
* get a crypto handler
*/
ceph::HeartbeatMap *_heartbeat_map;
+ ceph_spinlock_t _associated_objs_lock;
+ map<string, AssociatedSingletonObject*> _associated_objs;
+
// crypto
CryptoNone *_crypto_none;
CryptoAES *_crypto_aes;