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>
94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
#include "activation.hpp"
|
|
namespace activation {
|
|
int Engine::reserve(Handle& handle, int count)
|
|
{
|
|
if (handle.view.prepared + count > share_limit) {
|
|
return ownership;
|
|
}
|
|
const int before = handle.view.prepared;
|
|
for (int index = 0; index < count; ++index) {
|
|
const int result = prepare_one(handle);
|
|
if (result != ok) {
|
|
undo_prepared(handle, before);
|
|
return result;
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
int Engine::gate(Handle& handle, int count)
|
|
{
|
|
if (available(handle) < count) {
|
|
return ownership;
|
|
}
|
|
const int before = handle.view.enabled;
|
|
for (int index = 0; index < count; ++index) {
|
|
const int result = enable_one(handle);
|
|
if (result != ok) {
|
|
undo_enabled(handle, before);
|
|
return result;
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
int Engine::activate(Handle& handle, int count)
|
|
{
|
|
if (handle.view.prepared + count > share_limit) {
|
|
return ownership;
|
|
}
|
|
std::vector<int> journal;
|
|
int failure = ok;
|
|
for (int phase = 0; phase != 2 && failure == ok; ++phase) {
|
|
for (int step = 0; step != count; ++step) {
|
|
failure = phase == 0 ? prepare_one(handle) : enable_one(handle);
|
|
if (failure != ok) {
|
|
break;
|
|
}
|
|
journal.push_back(phase);
|
|
}
|
|
}
|
|
if (failure != ok) {
|
|
for (auto action = journal.rbegin(); action != journal.rend(); ++action) {
|
|
if (*action == 1) {
|
|
disable_one(handle);
|
|
} else {
|
|
unprepare_one(handle);
|
|
}
|
|
}
|
|
}
|
|
return failure;
|
|
}
|
|
int Engine::ungate(Handle& handle, int count)
|
|
{
|
|
if (handle.view.enabled < count) {
|
|
return ownership;
|
|
}
|
|
for (int index = 0; index < count; ++index) {
|
|
disable_one(handle);
|
|
}
|
|
return ok;
|
|
}
|
|
int Engine::release(Handle& handle, int count)
|
|
{
|
|
if (handle.view.prepared - handle.view.enabled < count) {
|
|
return ownership;
|
|
}
|
|
for (int index = 0; index < count; ++index) {
|
|
unprepare_one(handle);
|
|
}
|
|
return ok;
|
|
}
|
|
int Engine::deactivate(Handle& handle, int count)
|
|
{
|
|
if (handle.view.enabled < count) {
|
|
return ownership;
|
|
}
|
|
for (int index = 0; index < count; ++index) {
|
|
disable_one(handle);
|
|
}
|
|
for (int index = 0; index < count; ++index) {
|
|
unprepare_one(handle);
|
|
}
|
|
return ok;
|
|
}
|
|
}
|