icinga2/lib/base/objectlock.hpp
2026-03-02 15:36:59 +01:00

40 lines
695 B
C++

// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef OBJECTLOCK_H
#define OBJECTLOCK_H
#include "base/object.hpp"
namespace icinga
{
/**
* A scoped lock for Objects.
*/
struct ObjectLock
{
public:
ObjectLock(const Object::Ptr& object);
ObjectLock(const Object::Ptr& object, std::defer_lock_t);
ObjectLock(const Object *object);
ObjectLock(const ObjectLock&) = delete;
ObjectLock& operator=(const ObjectLock&) = delete;
~ObjectLock();
bool TryLock() noexcept;
void Lock();
void Unlock();
operator bool() const;
private:
const Object *m_Object{nullptr};
bool m_Locked{false};
};
}
#endif /* OBJECTLOCK_H */