mirror of
https://github.com/matrix-construct/construct
synced 2024-05-28 15:53:46 +02:00
ircd::ctx: Simplify ctx::list abi; tweak hot section.
This commit is contained in:
parent
cfaf6a90f1
commit
1627986fed
|
@ -31,10 +31,8 @@ namespace ircd::ctx
|
|||
struct ircd::ctx::list
|
||||
{
|
||||
struct node;
|
||||
using closure_bool_const = std::function<bool (const ctx &)>;
|
||||
using closure_const = std::function<void (const ctx &)>;
|
||||
using closure_bool = std::function<bool (ctx &)>;
|
||||
using closure = std::function<void (ctx &)>;
|
||||
using closure_const = util::closure_bool<std::function, const ctx &>;
|
||||
using closure = util::closure_bool<std::function, ctx &>;
|
||||
|
||||
private:
|
||||
ctx *head {nullptr};
|
||||
|
@ -56,29 +54,25 @@ struct ircd::ctx::list
|
|||
ctx *back() noexcept;
|
||||
|
||||
// iteration
|
||||
bool for_each(const closure_bool_const &) const;
|
||||
void for_each(const closure_const &) const;
|
||||
bool for_each(const closure_bool &);
|
||||
void for_each(const closure &);
|
||||
bool for_each(const closure_const &) const;
|
||||
bool for_each(const closure &);
|
||||
|
||||
// reverse iteration
|
||||
bool rfor_each(const closure_bool_const &) const;
|
||||
void rfor_each(const closure_const &) const;
|
||||
bool rfor_each(const closure_bool &);
|
||||
void rfor_each(const closure &);
|
||||
bool rfor_each(const closure_const &) const;
|
||||
bool rfor_each(const closure &);
|
||||
|
||||
bool empty() const noexcept;
|
||||
size_t size() const noexcept;
|
||||
|
||||
void push_front(ctx *const & = current) noexcept;
|
||||
void push_back(ctx *const & = current) noexcept;
|
||||
void push(ctx *const & = current) noexcept; // push_back
|
||||
void push_front(ctx * = current) noexcept;
|
||||
void push_back(ctx * = current) noexcept;
|
||||
void push(ctx * = current) noexcept; // push_back
|
||||
|
||||
ctx *pop_front() noexcept;
|
||||
ctx *pop_back() noexcept;
|
||||
ctx *pop() noexcept; // pop_front
|
||||
|
||||
void remove(ctx *const & = current) noexcept;
|
||||
void remove(ctx * = current) noexcept;
|
||||
|
||||
list() = default;
|
||||
list(list &&) noexcept;
|
||||
|
@ -132,7 +126,7 @@ noexcept
|
|||
}
|
||||
|
||||
inline void
|
||||
ircd::ctx::list::push(ctx *const &c)
|
||||
ircd::ctx::list::push(ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
push_back(c);
|
||||
|
|
68
ircd/ctx.cc
68
ircd/ctx.cc
|
@ -291,7 +291,7 @@ ircd::ctx::ctx::jump()
|
|||
/// considered handled an another attempt to `wait()` can be made. Returns true
|
||||
/// if the context suspended and was notified. When a context wakes up the
|
||||
/// note counter is reset.
|
||||
[[gnu::visibility("hidden"), gnu::hot]]
|
||||
[[gnu::visibility("hidden")]]
|
||||
bool
|
||||
IRCD_CTX_STACK_PROTECT
|
||||
ircd::ctx::ctx::wait()
|
||||
|
@ -361,7 +361,7 @@ noexcept
|
|||
}
|
||||
|
||||
/// Wakes a context without a note (internal)
|
||||
[[gnu::visibility("hidden"), gnu::hot]]
|
||||
[[gnu::visibility("hidden")]]
|
||||
bool
|
||||
ircd::ctx::ctx::wake()
|
||||
noexcept try
|
||||
|
@ -1070,7 +1070,6 @@ noexcept -> void
|
|||
return;
|
||||
}};
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::continuation::leave()
|
||||
noexcept
|
||||
|
@ -1121,7 +1120,6 @@ noexcept
|
|||
ircd::ctx::current = nullptr;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::continuation::enter()
|
||||
{
|
||||
|
@ -2785,12 +2783,12 @@ ircd::ctx::condition_variable::waiting(const ctx &a)
|
|||
const noexcept
|
||||
{
|
||||
// for_each returns false if a was found
|
||||
return !q.for_each(list::closure_bool_const{[&a](const ctx &b)
|
||||
return !q.for_each([&a](const ctx &b)
|
||||
noexcept
|
||||
{
|
||||
// return false to break on equal
|
||||
return std::addressof(a) != std::addressof(b);
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -2947,12 +2945,12 @@ ircd::ctx::dock::waiting(const ctx &a)
|
|||
const noexcept
|
||||
{
|
||||
// for_each returns false if a was found
|
||||
return !q.for_each(list::closure_bool_const{[&a](const ctx &b)
|
||||
return !q.for_each([&a](const ctx &b)
|
||||
noexcept
|
||||
{
|
||||
// return false to break on equal
|
||||
return std::addressof(a) != std::addressof(b);
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -2986,7 +2984,7 @@ noexcept
|
|||
//
|
||||
|
||||
void
|
||||
ircd::ctx::list::remove(ctx *const &c)
|
||||
ircd::ctx::list::remove(ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
assert(c);
|
||||
|
@ -3010,6 +3008,7 @@ noexcept
|
|||
prev(c) = nullptr;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
ircd::ctx::ctx *
|
||||
ircd::ctx::list::pop_back()
|
||||
noexcept
|
||||
|
@ -3042,6 +3041,7 @@ noexcept
|
|||
return tail;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
ircd::ctx::ctx *
|
||||
ircd::ctx::list::pop_front()
|
||||
noexcept
|
||||
|
@ -3074,8 +3074,9 @@ noexcept
|
|||
return head;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::list::push_front(ctx *const &c)
|
||||
ircd::ctx::list::push_front(ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
assert(next(c) == nullptr);
|
||||
|
@ -3095,8 +3096,9 @@ noexcept
|
|||
head = c;
|
||||
}
|
||||
|
||||
[[gnu::hot]]
|
||||
void
|
||||
ircd::ctx::list::push_back(ctx *const &c)
|
||||
ircd::ctx::list::push_back(ctx *const c)
|
||||
noexcept
|
||||
{
|
||||
assert(next(c) == nullptr);
|
||||
|
@ -3130,25 +3132,21 @@ const noexcept
|
|||
return i;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
ircd::ctx::list::rfor_each(const closure &closure)
|
||||
{
|
||||
for(ctx *tail{this->tail}; tail; tail = prev(tail))
|
||||
closure(*tail);
|
||||
if(!closure(*tail))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
ircd::ctx::list::rfor_each(const closure_const &closure)
|
||||
const
|
||||
{
|
||||
for(const ctx *tail{this->tail}; tail; tail = prev(tail))
|
||||
closure(*tail);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::ctx::list::rfor_each(const closure_bool &closure)
|
||||
{
|
||||
for(ctx *tail{this->tail}; tail; tail = prev(tail))
|
||||
if(!closure(*tail))
|
||||
return false;
|
||||
|
||||
|
@ -3156,33 +3154,7 @@ ircd::ctx::list::rfor_each(const closure_bool &closure)
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::ctx::list::rfor_each(const closure_bool_const &closure)
|
||||
const
|
||||
{
|
||||
for(const ctx *tail{this->tail}; tail; tail = prev(tail))
|
||||
if(!closure(*tail))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::list::for_each(const closure &closure)
|
||||
{
|
||||
for(ctx *head{this->head}; head; head = next(head))
|
||||
closure(*head);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::list::for_each(const closure_const &closure)
|
||||
const
|
||||
{
|
||||
for(const ctx *head{this->head}; head; head = next(head))
|
||||
closure(*head);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::ctx::list::for_each(const closure_bool &closure)
|
||||
{
|
||||
for(ctx *head{this->head}; head; head = next(head))
|
||||
if(!closure(*head))
|
||||
|
@ -3192,7 +3164,7 @@ ircd::ctx::list::for_each(const closure_bool &closure)
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::ctx::list::for_each(const closure_bool_const &closure)
|
||||
ircd::ctx::list::for_each(const closure_const &closure)
|
||||
const
|
||||
{
|
||||
for(const ctx *head{this->head}; head; head = next(head))
|
||||
|
|
Loading…
Reference in a new issue