mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
reference_counted_object and reference_counted_message specialisations
This commit is contained in:
parent
cbf07b053c
commit
ecee02d41d
@ -54,7 +54,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
// Reference counted message type.
|
||||
//***************************************************************************
|
||||
template <typename TMessage, typename TCounter = void>
|
||||
template <typename TMessage, typename TCounter>
|
||||
class reference_counted_message : public etl::ireference_counted_message
|
||||
{
|
||||
public:
|
||||
@ -110,7 +110,7 @@ namespace etl
|
||||
/// \tparam TMessage The type to be reference counted.
|
||||
//***************************************************************************
|
||||
template <typename TMessage>
|
||||
class atomic_counted_message : virtual public etl::reference_counted_message<TMessage, etl::atomic_uint32_t>
|
||||
class atomic_counted_message : virtual public etl::reference_counted_message<TMessage, etl::atomic_int32_t>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -119,12 +119,12 @@ namespace etl
|
||||
/// \param msg The message to count.
|
||||
//***************************************************************************
|
||||
atomic_counted_message(const TMessage& msg_)
|
||||
: reference_counted_message<TMessage, etl::atomic_uint32_t>(msg_)
|
||||
: reference_counted_message<TMessage, etl::atomic_int32_t>(msg_)
|
||||
{
|
||||
}
|
||||
|
||||
typedef typename reference_counted_message<TMessage, etl::atomic_uint32_t>::message_type message_type;
|
||||
typedef typename reference_counted_message<TMessage, etl::atomic_uint32_t>::counter_type counter_type;
|
||||
typedef typename reference_counted_message<TMessage, etl::atomic_int32_t>::message_type message_type;
|
||||
typedef typename reference_counted_message<TMessage, etl::atomic_int32_t>::counter_type counter_type;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -180,6 +180,27 @@ namespace etl
|
||||
/// The reference counted object.
|
||||
etl::reference_counted_object<TMessage, void> rc_object;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Synonym for reference_counted_message<TMessage, void>
|
||||
/// \tparam TObject The type stored in the object.
|
||||
//***************************************************************************
|
||||
template <typename TMessage>
|
||||
class uncounted_message : public etl::reference_counted_message<TMessage, void>
|
||||
{
|
||||
public:
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructor.
|
||||
//***************************************************************************
|
||||
uncounted_message(const TMessage& msg_)
|
||||
: reference_counted_message<TMessage, void>(msg_)
|
||||
{
|
||||
}
|
||||
|
||||
typedef typename reference_counted_message<TMessage, void>::message_type message_type;
|
||||
typedef typename reference_counted_message<TMessage, void>::counter_type counter_type;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -55,7 +55,7 @@ namespace etl
|
||||
/// \tparam TObject The type to be reference counted.
|
||||
/// \tparam TCounter The type to use as the counter.
|
||||
//***************************************************************************
|
||||
template <typename TObject, typename TCounter = void>
|
||||
template <typename TObject, typename TCounter>
|
||||
class reference_counted_object : public etl::ireference_counted_object
|
||||
{
|
||||
public:
|
||||
@ -101,6 +101,8 @@ namespace etl
|
||||
//***************************************************************************
|
||||
ETL_NODISCARD virtual uint32_t decrement_reference_count() ETL_OVERRIDE
|
||||
{
|
||||
assert(reference_count > 0);
|
||||
|
||||
return uint32_t(--reference_count);
|
||||
}
|
||||
|
||||
@ -129,7 +131,7 @@ namespace etl
|
||||
/// \tparam TObject The type to be reference counted.
|
||||
//***************************************************************************
|
||||
template <typename TObject>
|
||||
class atomic_counted_object : public etl::reference_counted_object<TObject, etl::atomic_uint32_t>
|
||||
class atomic_counted_object : public etl::reference_counted_object<TObject, etl::atomic_int32_t>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -137,12 +139,12 @@ namespace etl
|
||||
/// Constructor.
|
||||
//***************************************************************************
|
||||
atomic_counted_object(const TObject& object_)
|
||||
: reference_counted_object<TObject, etl::atomic_uint32_t>(object_)
|
||||
: reference_counted_object<TObject, etl::atomic_int32_t>(object_)
|
||||
{
|
||||
}
|
||||
|
||||
typedef typename reference_counted_object<TObject, etl::atomic_uint32_t>::value_type value_type;
|
||||
typedef typename reference_counted_object<TObject, etl::atomic_uint32_t>::counter_type counter_type;
|
||||
typedef typename reference_counted_object<TObject, etl::atomic_int32_t>::value_type value_type;
|
||||
typedef typename reference_counted_object<TObject, etl::atomic_int32_t>::counter_type counter_type;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -217,6 +219,27 @@ namespace etl
|
||||
|
||||
TObject object; // The object being reference counted.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Synonym for reference_counted_object<TObject, void>
|
||||
/// \tparam TObject The type stored in the object.
|
||||
//***************************************************************************
|
||||
template <typename TObject>
|
||||
class uncounted_object : public etl::reference_counted_object<TObject, void>
|
||||
{
|
||||
public:
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructor.
|
||||
//***************************************************************************
|
||||
uncounted_object(const TObject& object_)
|
||||
: reference_counted_object<TObject>(object_)
|
||||
{
|
||||
}
|
||||
|
||||
typedef typename reference_counted_object<TObject, void>::value_type value_type;
|
||||
typedef typename reference_counted_object<TObject, void>::counter_type counter_type;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user