100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
192 lines
5.3 KiB
C++
192 lines
5.3 KiB
C++
#include "interest.hpp"
|
|
namespace interest {
|
|
Reactor::Reactor() {
|
|
for (auto& token : ring_) {
|
|
token.fd = -1;
|
|
token.generation = 0;
|
|
}
|
|
}
|
|
bool Reactor::fd_valid(std::int64_t fd) {
|
|
return fd >= 0 && fd < DescriptorLimit;
|
|
}
|
|
bool Reactor::mask_valid(std::int64_t mask) {
|
|
return mask >= 0 && mask <= (Input | Output);
|
|
}
|
|
bool Reactor::mode_valid(std::int64_t mode) {
|
|
return mode >= 0 && mode <= (Edge | OneShot);
|
|
}
|
|
bool Reactor::cookie_valid(std::int64_t cookie) {
|
|
return cookie >= 0 && cookie <= 2147483647;
|
|
}
|
|
bool Reactor::raw_valid(std::int64_t bits) {
|
|
return bits >= 0 && bits <= (Input | Output | Error | Hangup);
|
|
}
|
|
bool Reactor::batch_valid(std::int64_t maximum) {
|
|
return maximum >= 1 && maximum <= InterestLimit;
|
|
}
|
|
int Reactor::control_domain(std::int64_t fd, std::int64_t mask,
|
|
std::int64_t mode, std::int64_t cookie) const {
|
|
if (!fd_valid(fd)) {
|
|
return Invalid;
|
|
}
|
|
if (!mask_valid(mask)) {
|
|
return Invalid;
|
|
}
|
|
if (!mode_valid(mode)) {
|
|
return Invalid;
|
|
}
|
|
if (!cookie_valid(cookie)) {
|
|
return Invalid;
|
|
}
|
|
return Ok;
|
|
}
|
|
int Reactor::live_status(std::int64_t fd) const {
|
|
if (!fd_valid(fd)) {
|
|
return Invalid;
|
|
}
|
|
if (!descriptors_[static_cast<int>(fd)].live) {
|
|
return Closed;
|
|
}
|
|
return Ok;
|
|
}
|
|
int Reactor::registered_status(std::int64_t fd) const {
|
|
int status = live_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
if (!registrations_[static_cast<int>(fd)].present) {
|
|
return Missing;
|
|
}
|
|
return Ok;
|
|
}
|
|
int Reactor::open(std::int64_t fd) {
|
|
if (!fd_valid(fd)) {
|
|
return Invalid;
|
|
}
|
|
int key = static_cast<int>(fd);
|
|
Descriptor& descriptor = descriptors_[key];
|
|
if (descriptor.live) {
|
|
return Exists;
|
|
}
|
|
descriptor.live = true;
|
|
descriptor.generation += 1;
|
|
descriptor.raw = 0;
|
|
return Ok;
|
|
}
|
|
void Reactor::forget_registration(int fd) {
|
|
Registration& registration = registrations_[fd];
|
|
if (!registration.present) {
|
|
return;
|
|
}
|
|
erase(fd);
|
|
registration = Registration{};
|
|
registration_count_ -= 1;
|
|
}
|
|
int Reactor::close(std::int64_t fd) {
|
|
int status = live_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
int key = static_cast<int>(fd);
|
|
forget_registration(key);
|
|
Descriptor& descriptor = descriptors_[key];
|
|
descriptor.live = false;
|
|
descriptor.raw = 0;
|
|
return Ok;
|
|
}
|
|
void Reactor::initialize_registration(int fd, int mask, int mode,
|
|
std::int64_t cookie) {
|
|
Registration& registration = registrations_[fd];
|
|
registration.present = true;
|
|
registration.generation = descriptors_[fd].generation;
|
|
registration.mask = mask;
|
|
registration.mode = mode;
|
|
registration.cookie = cookie;
|
|
registration.armed = true;
|
|
registration.pending = effective(fd);
|
|
registration.queued = false;
|
|
registration_count_ += 1;
|
|
synchronize(fd);
|
|
}
|
|
int Reactor::add(std::int64_t fd, std::int64_t mask, std::int64_t mode,
|
|
std::int64_t cookie) {
|
|
int status = control_domain(fd, mask, mode, cookie);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
status = live_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
int key = static_cast<int>(fd);
|
|
if (registrations_[key].present) {
|
|
return Exists;
|
|
}
|
|
if (registration_count_ == InterestLimit) {
|
|
return Full;
|
|
}
|
|
initialize_registration(key, static_cast<int>(mask),
|
|
static_cast<int>(mode), cookie);
|
|
return Ok;
|
|
}
|
|
void Reactor::reconfigure(int fd, int mask, int mode, std::int64_t cookie) {
|
|
Registration& registration = registrations_[fd];
|
|
registration.mask = mask;
|
|
registration.mode = mode;
|
|
registration.cookie = registration.cookie;
|
|
registration.armed = true;
|
|
registration.pending = effective(fd);
|
|
synchronize(fd);
|
|
}
|
|
int Reactor::modify(std::int64_t fd, std::int64_t mask, std::int64_t mode,
|
|
std::int64_t cookie) {
|
|
int status = control_domain(fd, mask, mode, cookie);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
status = registered_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
reconfigure(static_cast<int>(fd), static_cast<int>(mask),
|
|
static_cast<int>(mode), cookie);
|
|
return Ok;
|
|
}
|
|
int Reactor::remove(std::int64_t fd) {
|
|
int status = registered_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
forget_registration(static_cast<int>(fd));
|
|
return Ok;
|
|
}
|
|
int Reactor::set_ready(std::int64_t fd, std::int64_t bits) {
|
|
if (!fd_valid(fd) || !raw_valid(bits)) {
|
|
return Invalid;
|
|
}
|
|
int status = live_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
int key = static_cast<int>(fd);
|
|
int previous = effective(key);
|
|
descriptors_[key].raw = static_cast<int>(bits);
|
|
readiness_changed(key, previous);
|
|
return Ok;
|
|
}
|
|
int Reactor::clear_ready(std::int64_t fd, std::int64_t bits) {
|
|
if (!fd_valid(fd) || !raw_valid(bits)) {
|
|
return Invalid;
|
|
}
|
|
int status = live_status(fd);
|
|
if (status != Ok) {
|
|
return status;
|
|
}
|
|
int key = static_cast<int>(fd);
|
|
int previous = effective(key);
|
|
descriptors_[key].raw &= ~static_cast<int>(bits);
|
|
readiness_changed(key, previous);
|
|
return Ok;
|
|
}
|
|
}
|