Skip to content

Latest commit

 

History

History
70 lines (60 loc) · 2.68 KB

File metadata and controls

70 lines (60 loc) · 2.68 KB
#include <coroutine>

template <typename T>
struct checks
{
    static_assert(sizeof(std::coroutine_handle<T>) == sizeof(void*));
    static_assert(alignof(std::coroutine_handle<T>) == alignof(void*));

    static std::coroutine_handle<T> coro_from_promise(T& y)
    {
        return std::coroutine_handle<T>::from_promise(y);
    }

    static void* handle_coro(std::coroutine_handle<T> y)
    {
        return y.address();
    }

    static void* handle_coro(T& y)
    {
        return handle_coro(coro_from_promise(y));
    }

    static void resume_coro(T& y)
    {
        return coro_from_promise(y).resume();
    }

    static void destroy_coro(T& y)
    {
        return coro_from_promise(y).destroy();
    }
};

struct empty_t {};
struct overaligned
{
    alignas(256) char _[256];
};

template struct checks<empty_t>;
template struct checks<overaligned>;

esp::idf::events

Caveats

  • When subscribing to events with varying payload sizes we will (currently) read beyond the boundary of smaller (than max) payloads
    • nullptrs are not read and instead we effectively do memset(0, max_size) for that
    • this is technically undefined behavior but practically fine (as we later on ignore the extra bytes we've read)
    • Maybe keep track of payload sizes in fd_context::subscriptions?
  • Should probably store the message queue as ring buffer instead
    • or at least bounded
  • Maybe add a 'size' field to message header (iff payload sizes vary)?
  • Maybe do bit packing/compression on header fields?
    • watch out not to go to zero-sized message for subscription to single void event