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>
91 lines
2.3 KiB
C++
91 lines
2.3 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;
|
|
}
|
|
const int prepared_before = handle.view.prepared;
|
|
const int enabled_before = handle.view.enabled;
|
|
for (int index = 0; index < count; ++index) {
|
|
const int result = prepare_one(handle);
|
|
if (result != ok) {
|
|
undo_prepared(handle, prepared_before);
|
|
return result;
|
|
}
|
|
}
|
|
for (int index = 0; index < count; ++index) {
|
|
const int result = enable_one(handle);
|
|
if (result != ok) {
|
|
undo_enabled(handle, enabled_before);
|
|
undo_prepared(handle, prepared_before);
|
|
return result;
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
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;
|
|
}
|
|
}
|