From b6149b429eb4fa166f829f80ecbfdc8c3de5a90b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 10 Sep 2019 10:19:50 -0700 Subject: [PATCH] ircd::ctx::dock: Add noexcept to interface observers. ircd::ctx: Propagate noexcept on hot leafs; ircd::ctx::list: Deinline size(). --- include/ircd/ctx/dock.h | 4 +-- include/ircd/ctx/list.h | 57 +++++++++++++++++----------------------- include/ircd/ctx/mutex.h | 14 +++++----- ircd/ctx.cc | 43 ++++++++++++++++++++++++++++-- modules/console.cc | 6 +++-- 5 files changed, 79 insertions(+), 45 deletions(-) diff --git a/include/ircd/ctx/dock.h b/include/ircd/ctx/dock.h index fcd1bb748..78e5383ee 100644 --- a/include/ircd/ctx/dock.h +++ b/include/ircd/ctx/dock.h @@ -28,8 +28,8 @@ class ircd::ctx::dock void notify(ctx &) noexcept; public: - bool empty() const; - size_t size() const; + bool empty() const noexcept; + size_t size() const noexcept; template bool wait_until(time_point&&, const predicate &); template bool wait_until(time_point&&); diff --git a/include/ircd/ctx/list.h b/include/ircd/ctx/list.h index db7e5ff13..efd4bb23b 100644 --- a/include/ircd/ctx/list.h +++ b/include/ircd/ctx/list.h @@ -37,16 +37,16 @@ struct ircd::ctx::list ctx *tail {nullptr}; // Get next or prev entry in ctx - static const ctx *next(const ctx *const &); - static const ctx *prev(const ctx *const &); - static ctx *&next(ctx *const &); - static ctx *&prev(ctx *const &); + static const ctx *next(const ctx *const &) noexcept; + static const ctx *prev(const ctx *const &) noexcept; + static ctx *&next(ctx *const &) noexcept; + static ctx *&prev(ctx *const &) noexcept; public: - const ctx *front() const; - const ctx *back() const; - ctx *front(); - ctx *back(); + const ctx *front() const noexcept; + const ctx *back() const noexcept; + ctx *front() noexcept; + ctx *back() noexcept; // iteration bool for_each(const std::function &) const; @@ -60,18 +60,18 @@ struct ircd::ctx::list void rfor_each(const std::function &) const; void rfor_each(const std::function &); - bool empty() const; - size_t size() const; + bool empty() const noexcept; + size_t size() const noexcept; - void push_front(ctx *const & = current); - void push_back(ctx *const & = current); - void push(ctx *const & = current); // push_back + void push_front(ctx *const & = current) noexcept; + void push_back(ctx *const & = current) noexcept; + void push(ctx *const & = current) noexcept; // push_back - ctx *pop_front(); - ctx *pop_back(); - ctx *pop(); // pop_front + ctx *pop_front() noexcept; + ctx *pop_back() noexcept; + ctx *pop() noexcept; // pop_front - void remove(ctx *const & = current); + void remove(ctx *const & = current) noexcept; list() = default; list(list &&) noexcept; @@ -119,32 +119,21 @@ noexcept inline ircd::ctx::ctx * ircd::ctx::list::pop() +noexcept { return pop_front(); } inline void ircd::ctx::list::push(ctx *const &c) +noexcept { push_back(c); } -inline size_t -ircd::ctx::list::size() -const -{ - size_t i{0}; - for_each([&i](const ctx &) - { - ++i; - }); - - return i; -} - inline bool ircd::ctx::list::empty() -const +const noexcept { assert((!head && !tail) || (head && tail)); return !head; @@ -152,26 +141,28 @@ const inline ircd::ctx::ctx * ircd::ctx::list::back() +noexcept { return tail; } inline ircd::ctx::ctx * ircd::ctx::list::front() +noexcept { return head; } inline const ircd::ctx::ctx * ircd::ctx::list::back() -const +const noexcept { return tail; } inline const ircd::ctx::ctx * ircd::ctx::list::front() -const +const noexcept { return head; } diff --git a/include/ircd/ctx/mutex.h b/include/ircd/ctx/mutex.h index e9b7d5ec9..2223333a7 100644 --- a/include/ircd/ctx/mutex.h +++ b/include/ircd/ctx/mutex.h @@ -27,17 +27,17 @@ class ircd::ctx::mutex bool m; public: - bool locked() const; - size_t waiting() const; + bool locked() const noexcept; + size_t waiting() const noexcept; - bool try_lock(); + bool try_lock() noexcept; template bool try_lock_until(const time_point &); template bool try_lock_for(const duration &); void lock(); void unlock(); - mutex(); + mutex() noexcept; mutex(mutex &&) noexcept; mutex(const mutex &) = delete; mutex &operator=(mutex &&) noexcept; @@ -47,6 +47,7 @@ class ircd::ctx::mutex inline ircd::ctx::mutex::mutex() +noexcept :m{false} { } @@ -125,6 +126,7 @@ ircd::ctx::mutex::try_lock_until(const time_point &tp) inline bool ircd::ctx::mutex::try_lock() +noexcept { if(locked()) return false; @@ -135,14 +137,14 @@ ircd::ctx::mutex::try_lock() inline size_t ircd::ctx::mutex::waiting() -const +const noexcept { return q.size(); } inline bool ircd::ctx::mutex::locked() -const +const noexcept { return m; } diff --git a/ircd/ctx.cc b/ircd/ctx.cc index b9e35d313..ce4e32bec 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -751,6 +751,7 @@ noexcept // uinterruptible // +[[gnu::hot]] ircd::ctx::this_ctx::uninterruptible::uninterruptible() :theirs { @@ -760,6 +761,7 @@ ircd::ctx::this_ctx::uninterruptible::uninterruptible() interruptible(false); } +[[gnu::hot]] ircd::ctx::this_ctx::uninterruptible::~uninterruptible() noexcept(false) { @@ -770,6 +772,7 @@ noexcept(false) // uninterruptible::nothrow // +[[gnu::hot]] ircd::ctx::this_ctx::uninterruptible::nothrow::nothrow() noexcept :theirs @@ -780,6 +783,7 @@ noexcept interruptible(false, std::nothrow); } +[[gnu::hot]] ircd::ctx::this_ctx::uninterruptible::nothrow::~nothrow() noexcept { @@ -1006,6 +1010,7 @@ ircd::ctx::continuation::noop_interruptor{[] // continuation // +[[gnu::hot]] ircd::ctx::continuation::continuation(const predicate &pred, const interruptor &intr, const yield_closure &closure) @@ -1083,6 +1088,7 @@ ircd::ctx::continuation::continuation(const predicate &pred, } } +[[gnu::hot]] ircd::ctx::continuation::~continuation() noexcept { @@ -1105,6 +1111,7 @@ noexcept // pointer while the context is awake. } +[[gnu::hot]] ircd::ctx::continuation::operator boost::asio::yield_context &() noexcept @@ -1114,6 +1121,7 @@ noexcept return *self->yc; } +[[gnu::hot]] ircd::ctx::continuation::operator const boost::asio::yield_context &() const noexcept @@ -2705,7 +2713,7 @@ noexcept /// The number of contexts waiting in the queue. size_t ircd::ctx::dock::size() -const +const noexcept { return q.size(); } @@ -2713,7 +2721,7 @@ const /// The number of contexts waiting in the queue. bool ircd::ctx::dock::empty() -const +const noexcept { return q.empty(); } @@ -2723,8 +2731,10 @@ const // ctx_list.h // +[[gnu::hot]] void ircd::ctx::list::remove(ctx *const &c) +noexcept { assert(c); @@ -2747,8 +2757,10 @@ ircd::ctx::list::remove(ctx *const &c) prev(c) = nullptr; } +[[gnu::hot]] ircd::ctx::ctx * ircd::ctx::list::pop_back() +noexcept { const auto tail { @@ -2778,8 +2790,10 @@ ircd::ctx::list::pop_back() return tail; } +[[gnu::hot]] ircd::ctx::ctx * ircd::ctx::list::pop_front() +noexcept { const auto head { @@ -2809,8 +2823,10 @@ ircd::ctx::list::pop_front() return head; } +[[gnu::hot]] void ircd::ctx::list::push_front(ctx *const &c) +noexcept { assert(next(c) == nullptr); assert(prev(c) == nullptr); @@ -2829,8 +2845,10 @@ ircd::ctx::list::push_front(ctx *const &c) head = c; } +[[gnu::hot]] void ircd::ctx::list::push_back(ctx *const &c) +noexcept { assert(next(c) == nullptr); assert(prev(c) == nullptr); @@ -2849,6 +2867,19 @@ ircd::ctx::list::push_back(ctx *const &c) tail = c; } +size_t +ircd::ctx::list::size() +const noexcept +{ + size_t i{0}; + for_each([&i](const ctx &) + { + ++i; + }); + + return i; +} + void ircd::ctx::list::rfor_each(const std::function &closure) { @@ -2921,29 +2952,37 @@ const return true; } +[[gnu::hot]] ircd::ctx::ctx *& ircd::ctx::list::prev(ctx *const &c) +noexcept { assert(c); return c->node.prev; } +[[gnu::hot]] ircd::ctx::ctx *& ircd::ctx::list::next(ctx *const &c) +noexcept { assert(c); return c->node.next; } +[[gnu::hot]] const ircd::ctx::ctx * ircd::ctx::list::prev(const ctx *const &c) +noexcept { assert(c); return c->node.prev; } +[[gnu::hot]] const ircd::ctx::ctx * ircd::ctx::list::next(const ctx *const &c) +noexcept { assert(c); return c->node.next; diff --git a/modules/console.cc b/modules/console.cc index 879841316..5f924d3c8 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5101,8 +5101,10 @@ console_cmd__net__host(opt &out, const string_view &line) net::dns::resolve(hostport, opts, cbarr); const ctx::uninterruptible ui; - while(!done) - dock.wait(); + dock.wait([&done] + { + return done; + }); if(eptr) std::rethrow_exception(eptr);