Add GetLatestSlot and GetLatestSample functionality - #208
Conversation
|
@muhseth please fix conflicts. |
| @@ -38,6 +38,55 @@ EventDataControlCompositeImpl<AtomicIndirectorType>::EventDataControlCompositeIm | |||
| CheckForValidDataControls(); | |||
| } | |||
|
|
|||
| template <template <class> class AtomicIndirectorType> | |||
| score::cpp::optional<SlotIndexType> EventDataControlCompositeImpl<AtomicIndirectorType>::FindLatestReadableSlotIndex( | |||
There was a problem hiding this comment.
You should instead change existing EventDataControlCompositeImpl::GetLatestTimestamp()! You are mostly duplicating code here. The new/refactored function should be named GetLatestSlot and it should return the index PLUS the timestamp!
And please take into account, what I have written here: Ticket-253464
There was a problem hiding this comment.
Done.
I have removed GetLatestTimeStamp function and corresponding upper layer code.
As I see it is not used any where.
| slot_index < static_cast<SlotIndexType>(control.state_slots_.size()); | ||
| ++slot_index) | ||
| { | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(static_cast<std::size_t>(slot_index) < control.state_slots_.size()); |
There was a problem hiding this comment.
? Why this assert? I do not get it.
There was a problem hiding this comment.
I have removed it. As I see it there is no needed of it.
I have kept it as it was the part of previous code.
c4ffb3a to
f0c0b32
Compare
| @@ -39,6 +39,53 @@ EventDataControlComposite<AtomicIndirectorType>::EventDataControlComposite(Event | |||
| CheckForValidDataControls(); | |||
| } | |||
|
|
|||
| template <template <class> class AtomicIndirectorType> | |||
There was a problem hiding this comment.
You have to be aware, that you have to align your changes with Brenbdans massive change here: #268
I.e. imho it makes sense, that you base your work on Brendans PR!
| @@ -39,6 +39,53 @@ EventDataControlComposite<AtomicIndirectorType>::EventDataControlComposite(Event | |||
| CheckForValidDataControls(); | |||
| } | |||
|
|
|||
| template <template <class> class AtomicIndirectorType> | |||
| score::cpp::optional<SlotIndexType> EventDataControlComposite<AtomicIndirectorType>::FindLatestReadableSlotIndex( | |||
There was a problem hiding this comment.
What does "readable" mean?
Just: FindNewestSlot ?
There was a problem hiding this comment.
I think what Wahaj means is "FindLatestReferencedSlotIndex". I think it makes sense because just "newest" could also mean newest available slot to allocate in which isn't what we want.
| @@ -43,7 +40,7 @@ auto EventSlotStatus::GetTimeStamp() const noexcept -> EventTimeStamp | |||
|
|
|||
| auto EventSlotStatus::IsInvalid() const noexcept -> bool | |||
| { | |||
| return data_ == INVALID_EVENT; | |||
| return data_ == static_cast<value_type>(InvalidTimestamp); | |||
There was a problem hiding this comment.
This cast looks "odd" to me!
Our EventSlotStatus::value_type is an uint64 ... the timestamp is a uint32!
An invalid event-slot status technically means:
The timestamp part is 0 (upper32 bit)
the ref-count part is 0 (lower 32 bit)
Just casting the timestamp part does miss this a bit ... if you want to be more "expressive" you could write something like:
constexpr EventSlotStatus::value_type INVALID_EVENT = (InvalidTimestamp <<32) | ZeroRefCount)
but this is "overdone" -> you could simply document INVALID_EVENT = 0u means an invalid timestamp and zero refcount ...
There was a problem hiding this comment.
i have made the changes as suggested.
| @@ -58,7 +55,7 @@ auto EventSlotStatus::MarkInWriting() noexcept -> void | |||
|
|
|||
| auto EventSlotStatus::MarkInvalid() noexcept -> void | |||
| { | |||
| data_ = INVALID_EVENT; | |||
| data_ = static_cast<value_type>(InvalidTimestamp); | |||
| @@ -251,6 +250,38 @@ Result<impl::SampleAllocateePtr<SampleType>> SkeletonEvent<SampleType>::Allocate | |||
| } | |||
| } | |||
|
|
|||
| template <typename SampleType> | |||
| Result<SampleType> SkeletonEvent<SampleType>::GetLatestSample() noexcept | |||
There was a problem hiding this comment.
Ouch. Why are you returning the sample by value here??? We never do this. A sample can be several megabytes in size ... so why are you copying it here - all our zero-copy architecture goes through the roof then ... and applications may crash, because the value will end up on stack, which will overflow ...
I guess you will use/need this functionality, when implementing the Skeleton-side get() method? Or even/also the set-method, where you need to work on the latest existing sample ...?
But then you need to apply SamplePtr logic!
I.e. you refcount the latest sample ... and create a SamplPtr from it, which you return from here ...
At your caller-side (your get/set impl) you then copy the data from the SamplePtr to your method ReturnType/InArg and once you are done with the copying, you destroy the SamplPtr freeing the slot.
This way you have just ONE copy! With your approach taken here, you copy TWICE! You copy out from shm to your sampl variable and then you copy from that variable back intro the call-queue! And this already expects, that you have RVO (which I guess is mandatory right now) ... but again - your caller side will crash, because the returned value (with RVO) will land most likely on stack and might explode there (if it is large).
| { | ||
| const auto sample = event_data_storage_->at(static_cast<std::uint64_t>(slot.GetIndex())); | ||
|
|
||
| if (slot.IsValidQM()) |
There was a problem hiding this comment.
OK - so here you are doing "manually", what should be the job of the SamplePtr dtor
f0c0b32 to
a65dc2c
Compare
a65dc2c to
636762e
Compare
85d878a to
4f7e4d4
Compare
7dbf113 to
e29d097
Compare
| @@ -236,7 +236,7 @@ template <template <class> class AtomicIndirectorType> | |||
| // coverity[autosar_cpp14_a15_5_3_violation : FALSE] | |||
| EventSlotStatus::EventTimeStamp EventDataControlComposite<AtomicIndirectorType>::GetLatestTimestamp() const noexcept | |||
| { | |||
| EventSlotStatus::EventTimeStamp latest_time_stamp{1U}; | |||
| EventSlotStatus::EventTimeStamp latest_time_stamp{EventSlotStatus::UNINITIALIZED_TIMESTAMP}; | |||
6b35406 to
0c33ec5
Compare
4f9d931 to
ba5411b
Compare
ba5411b to
526ed04
Compare
526ed04 to
4c69ed4
Compare
No description provided.