pub trait IsParticipant:
Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn get_oldest(&self, _: EnabledToken) -> Option<CoarseInstant>;
fn reclaim(self: Arc<Self>, _: EnabledToken) -> ReclaimFuture;
}
Expand description
Participants provide an impl of the hooks in this trait
Trait implemented by client of the memtrack API.
§Panic handling, “unwind safety”
If these methods panic, the memory tracker will tear down its records of the participant, preventing future allocations.
But, it’s not guaranteed that these methods on IsParticipant
won’t be called again,
even if they have already panicked on a previous occasion.
Thus the implementations might see “broken invariants”
as discussed in the docs for std::panic::UnwindSafe
.
Nevertheless we don’t make RefUnwindSafe
a supertrait of IsParticipant
.
That would force the caller to mark all their methods unwind-safe,
which is unreasonable (and probably undesirable).
Variables which are IsParticipant
are often named particip
.
Required Methods§
Sourcefn get_oldest(&self, _: EnabledToken) -> Option<CoarseInstant>
fn get_oldest(&self, _: EnabledToken) -> Option<CoarseInstant>
Return the age of the oldest data held by this Participant
None
means this Participant holds no data.
§Performance and reentrancy
This function runs with the MemoryQuotaTracker
’s internal global lock held.
Therefore:
- It must be fast.
- it must not call back into methods from
tracker
. - It must not even
Clone
orDrop
aMemoryQuotaTracker
,Account
, orParticipation
.
Sourcefn reclaim(self: Arc<Self>, _: EnabledToken) -> ReclaimFuture
fn reclaim(self: Arc<Self>, _: EnabledToken) -> ReclaimFuture
Start memory reclamation
The Participant should start to free all of its memory,
and then return Reclaimed::Collapsing
.