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>
119 lines
3.2 KiB
C++
119 lines
3.2 KiB
C++
#include "state.hpp"
|
|
namespace notify {
|
|
Code Runtime::create(int queue, int capacity)
|
|
{
|
|
if (!Impl::queue_valid(queue) || !Impl::capacity_valid(capacity)) {
|
|
return Code::invalid;
|
|
}
|
|
Slot& slot = impl_->slots[queue];
|
|
if (slot.live) {
|
|
return Code::busy;
|
|
}
|
|
slot.activate(capacity);
|
|
impl_->counters.created += 1;
|
|
return Code::ok;
|
|
}
|
|
Code Runtime::close(int queue)
|
|
{
|
|
Code error = impl_->queue_error(queue);
|
|
if (error != Code::ok) {
|
|
return error;
|
|
}
|
|
Slot& slot = *impl_->lookup(queue);
|
|
impl_->counters.discarded += slot.messages.size();
|
|
impl_->counters.closed += 1;
|
|
slot.deactivate();
|
|
return Code::ok;
|
|
}
|
|
Code Runtime::arm(int queue, int owner, int cookie)
|
|
{
|
|
if (!Impl::queue_valid(queue) || !Impl::owner_valid(owner)) {
|
|
return Code::invalid;
|
|
}
|
|
Slot* slot = impl_->lookup(queue);
|
|
if (slot == nullptr) {
|
|
return Code::missing;
|
|
}
|
|
if (slot->registration.present()) {
|
|
return Code::busy;
|
|
}
|
|
impl_->register_owner(queue, owner, cookie);
|
|
return Code::ok;
|
|
}
|
|
Code Runtime::cancel(int queue, int owner)
|
|
{
|
|
if (!Impl::queue_valid(queue) || !Impl::owner_valid(owner)) {
|
|
return Code::invalid;
|
|
}
|
|
Slot* slot = impl_->lookup(queue);
|
|
if (slot == nullptr) {
|
|
return Code::missing;
|
|
}
|
|
if (slot->registration.present() && slot->registration.owner != owner) {
|
|
return Code::denied;
|
|
}
|
|
impl_->cancel_owner(queue);
|
|
return Code::ok;
|
|
}
|
|
Code Runtime::send(int queue, int id, int value)
|
|
{
|
|
if (!Impl::queue_valid(queue) || !Impl::message_valid(id, value)) {
|
|
return Code::invalid;
|
|
}
|
|
Slot* slot = impl_->lookup(queue);
|
|
if (slot == nullptr) {
|
|
return Code::missing;
|
|
}
|
|
if (static_cast<int>(slot->messages.size()) == slot->capacity) {
|
|
return Code::full;
|
|
}
|
|
bool was_empty = slot->messages.empty();
|
|
Message message;
|
|
message.id = id;
|
|
message.value = value;
|
|
slot->messages.push_back(message);
|
|
impl_->counters.sent += 1;
|
|
impl_->on_enqueue(queue, was_empty);
|
|
return Code::ok;
|
|
}
|
|
Result<Message> Runtime::receive(int queue)
|
|
{
|
|
Result<Message> output;
|
|
output.code = impl_->queue_error(queue);
|
|
if (output.code != Code::ok) {
|
|
return output;
|
|
}
|
|
Slot* slot = impl_->lookup(queue);
|
|
if (slot->messages.empty()) {
|
|
output.code = Code::empty;
|
|
return output;
|
|
}
|
|
output.value = slot->remove_front();
|
|
impl_->counters.received += 1;
|
|
return output;
|
|
}
|
|
Result<std::vector<Message>> Runtime::drain(int queue, int limit)
|
|
{
|
|
Result<std::vector<Message>> output;
|
|
if (!Impl::queue_valid(queue) || !Impl::limit_valid(limit)) {
|
|
output.code = Code::invalid;
|
|
return output;
|
|
}
|
|
Slot* slot = impl_->lookup(queue);
|
|
if (slot == nullptr) {
|
|
output.code = Code::missing;
|
|
return output;
|
|
}
|
|
int count = static_cast<int>(slot->messages.size());
|
|
if (count > limit) {
|
|
count = limit;
|
|
}
|
|
output.value.reserve(static_cast<std::size_t>(count));
|
|
for (int index = 0; index < count; ++index) {
|
|
output.value.push_back(slot->remove_front());
|
|
}
|
|
impl_->counters.received += static_cast<unsigned>(count);
|
|
return output;
|
|
}
|
|
}
|