From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
1.6 KiB
C++
84 lines
1.6 KiB
C++
#include "blink.hpp"
|
|
|
|
namespace blink {
|
|
PulseTimer::PulseTimer(Platform &platform)
|
|
: platform_(platform), handle_(-1), callback_(nullptr), context_(nullptr),
|
|
staged_callback_(nullptr), staged_context_(nullptr)
|
|
{
|
|
}
|
|
|
|
int PulseTimer::prepare(Callback callback, void *context)
|
|
{
|
|
if (prepared()) {
|
|
return busy;
|
|
}
|
|
staged_callback_ = callback;
|
|
staged_context_ = context;
|
|
int resource = platform_.create_timer(&PulseTimer::dispatch, this);
|
|
if (resource < 0) {
|
|
staged_callback_ = nullptr;
|
|
staged_context_ = nullptr;
|
|
return resource;
|
|
}
|
|
handle_ = resource;
|
|
return 0;
|
|
}
|
|
|
|
int PulseTimer::start(std::uint32_t period)
|
|
{
|
|
if (!prepared()) {
|
|
return missing;
|
|
}
|
|
callback_ = staged_callback_;
|
|
context_ = staged_context_;
|
|
int result = platform_.arm(handle_, period);
|
|
return result;
|
|
}
|
|
|
|
void PulseTimer::rearm(std::uint32_t period)
|
|
{
|
|
if (prepared()) {
|
|
platform_.arm(handle_, period);
|
|
}
|
|
}
|
|
|
|
void PulseTimer::cancel()
|
|
{
|
|
if (prepared()) {
|
|
platform_.cancel(handle_);
|
|
}
|
|
}
|
|
|
|
void PulseTimer::finish()
|
|
{
|
|
if (!prepared()) {
|
|
return;
|
|
}
|
|
platform_.drain(handle_);
|
|
platform_.destroy_timer(handle_);
|
|
handle_ = -1;
|
|
callback_ = nullptr;
|
|
context_ = nullptr;
|
|
staged_callback_ = nullptr;
|
|
staged_context_ = nullptr;
|
|
}
|
|
|
|
int PulseTimer::handle() const
|
|
{
|
|
return handle_;
|
|
}
|
|
|
|
bool PulseTimer::prepared() const
|
|
{
|
|
return handle_ >= 0;
|
|
}
|
|
|
|
void PulseTimer::dispatch(void *context)
|
|
{
|
|
auto *timer = static_cast<PulseTimer *>(context);
|
|
if (timer->callback_ != nullptr) {
|
|
timer->callback_(timer->context_);
|
|
}
|
|
}
|
|
}
|