mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-03 20:46:28 +00:00
feat(Object): provide a L_SYNC macro to synchronize Object's data
This commit is contained in:
parent
09d29ea39b
commit
057c4ca3b9
3 changed files with 24 additions and 2 deletions
|
|
@ -30,8 +30,13 @@
|
|||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class ObjectPrivate : public BaseObjectPrivate {
|
||||
protected:
|
||||
constexpr const Object::Lock &getLock () const {
|
||||
return lock;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, Variant> properties;
|
||||
Object::Lock lock;
|
||||
|
||||
L_DECLARE_PUBLIC(Object);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -46,4 +46,9 @@ shared_ptr<const Object> Object::getSharedFromThis () const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
inline const Object::Lock &Object::getLock () const {
|
||||
L_D();
|
||||
return d->getLock();
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -21,12 +21,21 @@
|
|||
#define _OBJECT_H_
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "base-object.h"
|
||||
#include "property-container.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
// Must be used in Object or ObjectPrivate.
|
||||
#define L_SYNC() \
|
||||
static_assert( \
|
||||
!std::is_base_of<Object, decltype(this)>::value && !std::is_base_of<ObjectPrivate, decltype(this)>::value, \
|
||||
"Unable to lock. Instance is not an Object or ObjectPrivate." \
|
||||
); \
|
||||
const std::lock_guard<Object::Lock> synchronized(const_cast<Object::Lock &>(getLock()));
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
/*
|
||||
|
|
@ -38,14 +47,17 @@ class LINPHONE_PUBLIC Object :
|
|||
public std::enable_shared_from_this<Object>,
|
||||
public BaseObject,
|
||||
public PropertyContainer {
|
||||
|
||||
public:
|
||||
typedef std::recursive_mutex Lock;
|
||||
|
||||
std::shared_ptr<Object> getSharedFromThis ();
|
||||
std::shared_ptr<const Object> getSharedFromThis () const;
|
||||
|
||||
protected:
|
||||
explicit Object (ObjectPrivate &p);
|
||||
|
||||
const Lock &getLock () const;
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(Object);
|
||||
L_DISABLE_COPY(Object);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue