0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-14 00:34:18 +01:00

ircd::ctx::promise_base: Add refcount(promise_base&) to suite.

This commit is contained in:
Jason Volk 2019-09-08 16:33:38 -07:00
parent 5b2216fb63
commit a6747ad3a0
2 changed files with 15 additions and 0 deletions

View file

@ -46,6 +46,7 @@ struct ircd::ctx::promise_base
static const promise_base *head(const shared_state_base &);
static const promise_base *head(const promise_base &);
static size_t refcount(const shared_state_base &);
static size_t refcount(const promise_base &);
static promise_base *head(shared_state_base &);
static promise_base *head(promise_base &);

View file

@ -2058,6 +2058,20 @@ ircd::ctx::promise_base::make_ready()
assert(!valid());
}
/// If no shared state anymore: refcount=0; otherwise the promise
/// list head from p.st->p resolves to at least &p which means refcount>=1
size_t
ircd::ctx::promise_base::refcount(const promise_base &p)
{
const auto ret
{
p.st? refcount(*p.st): 0UL
};
assert((p.st && ret >= 1) || (!p.st && !ret));
return ret;
}
/// Internal use; returns the number of copies of the promise reachable from
/// the linked list headed by the shared state. This is used to indicate when
/// the last copy has destructed which may result in a broken_promise exception