icinga2/lib/base/objectlock.hpp

39 lines
606 B
C++
Raw Permalink Normal View History

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2013-02-24 02:27:00 -05:00
#ifndef OBJECTLOCK_H
#define OBJECTLOCK_H
2014-05-25 10:23:35 -04:00
#include "base/object.hpp"
2013-03-16 16:18:53 -04:00
2013-02-24 02:27:00 -05:00
namespace icinga
{
/**
* A scoped lock for Objects.
*/
2017-12-31 01:22:16 -05:00
struct ObjectLock
{
2013-02-24 02:27:00 -05:00
public:
ObjectLock(const Object::Ptr& object);
2025-07-03 06:14:31 -04:00
ObjectLock(const Object::Ptr& object, std::defer_lock_t);
ObjectLock(const Object *object);
ObjectLock(const ObjectLock&) = delete;
ObjectLock& operator=(const ObjectLock&) = delete;
~ObjectLock();
2014-11-12 00:33:20 -05:00
void Lock();
void Unlock();
2013-02-24 02:27:00 -05:00
operator bool() const;
2013-02-24 02:27:00 -05:00
private:
const Object *m_Object{nullptr};
bool m_Locked{false};
2013-02-24 02:27:00 -05:00
};
}
#endif /* OBJECTLOCK_H */