Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noexcept specifiers where appropriate #91

Merged

Commits on Jul 15, 2024

  1. Add noexcept specifiers where appropriate

    We can mark the following as `noexcept`:
    - ~ScopedConnection
    - ~Signal
    - ConnectionHandle::disconnect
    - several move constructors
    
    There are some caveats though:
    When disconnecting, we need to lock the mutex in the ConnectionEvaluator
    and allocate in the GenerationalIndexArray, which can both throw
    exceptions.
    However, we currently do not have any out of memory guarantees in
    KDBindings, so terminating in that case should be a sufficient way of
    handling this case.
    The same goes for when locking a mutex isn't possible. This likely
    indicates some kind of OS issue from which we can't really recover, so
    terminating is appropriate.
    
    We could improve the situation by avoiding allocations in the GenerationalIndexArray
    when erasing slots.
    This would be possible by using an inline linked-list inside the array
    to store free indices.
    Which would save memory and would no longer require us to allocate
    memory when erasing entries.
    However, it's also not trivial to implement, so leave this as a TODO.
    
    Error checking in ConnectionEvaluator
    -------------------------------------
    This patch also adds some basic exception handling to the
    ConnectionEvaluator.
    It is now somewhat protected from slots disconnecting themselves while they are
    evaluated and slots throwing exceptions.
    However, this error-handling is rather basic and will simply **not**
    dequeue any slots while the evaluator is already evaluating and will
    dequeue all slots if any slot throws an exception.
    We could improve this situation by using a queue and popping elements 1-by-1
    when evaluating without actually iterating over it.
    That way we could erase from the queue while its being evaluated.
    And when a slot throws, calling evaluate again could simply continue
    with the next slot, instead of skipping all queued slots.
    
    However, we should ideally implement this queue as a ring-buffer to
    avoid excessive allocations by std::list or std::dequeu.
    But this isn't part of the STL, so would require us to roll our own
    ring-buffer implementation.
    
    For now, this error handling isn't publicly documented and throwing
    within a slot or dequeuing while evaluating remains *undefined*,
    so that we can improve the situation in the future.
    LeonMatthesKDAB committed Jul 15, 2024
    Configuration menu
    Copy the full SHA
    85f64b3 View commit details
    Browse the repository at this point in the history
  2. Document that throwing within a slot is UB

    We currently don't really deal with this correctly.
    Until we do so, at least mention that it's UB.
    LeonMatthesKDAB committed Jul 15, 2024
    Configuration menu
    Copy the full SHA
    db9891b View commit details
    Browse the repository at this point in the history