Skip to content

Add Thread::isCancelled and Operation::isCancelled - #43

Merged
jdolan merged 1 commit into
mainfrom
feature/is-cancelled
Oct 12, 2026
Merged

jdolan merged 1 commit into
mainfrom
feature/is-cancelled

Conversation

@jdolan

@jdolan jdolan commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thread::isCancelled and Operation::isCancelled are set from another thread while a function polls them. 2.3.0 asked callers to read them with __atomic_load_n(&thread->isCancelled, __ATOMIC_ACQUIRE), which put an atomics builtin at every call site.

  • The two fields are now @private.
  • Thread::isCancelled(const Thread *) and Operation::isCancelled(const Operation *) load the flag atomically (acquire, paired with the release store in cancel).
  • Objectively's own readers (ThreadPool, OperationQueue, URLSession) and the tests use the methods.
  • New Thread test for the method.

The interfaces change, so this bumps the version to 2.4.0. ObjectivelyGPU and ObjectivelyMVC need a rebuild and a >= 2.4.0 requirement. Quetoo's three call sites change to $(thread, isCancelled).

Testing

  • make check: 27 of 27 suites pass.
  • ThreadPool, OperationQueue and Thread: 600 runs under parallel load, no failures.
  • The Xcode build of the library passes.

🤖 Generated with Claude Code

Both flags are set from another thread while a function polls them, so
2.3.0 asked callers to read them with __atomic_load_n. That put an
atomics builtin at every call site. The flags are now @Private, and
each class has an isCancelled method that loads its flag atomically.

The interfaces change, so the version is now 2.4.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new Operation accessor lacks interface-level test coverage, and an existing test still accesses its private field directly.

1 open finding
What changed in this PR

Adds thread-safe cancellation accessors for Thread and Operation, replacing direct cancellation-flag reads.

Changes:

  • Adds atomic isCancelled methods and marks backing fields private.
  • Migrates internal callers and adds a Thread test.
  • Bumps the ABI version to 2.4.0.
File Description
Tests/​Objectively/​ThreadPool.c Uses the new Thread accessor.
Tests/​Objectively/​Thread.c Tests Thread cancellation state.
Sources/​Objectively/​URLSession.c Migrates cancellation checks.
Sources/​Objectively/​ThreadPool.c Migrates worker cancellation polling.
Sources/​Objectively/​Thread.h Declares the cancellation accessor.
Sources/​Objectively/​Thread.c Implements atomic cancellation reads.
Sources/​Objectively/​OperationQueue.c Uses the Operation accessor.
Sources/​Objectively/​Operation.h Declares the cancellation accessor.
Sources/​Objectively/​Operation.c Implements atomic cancellation reads.
configure.ac Bumps the version to 2.4.0.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +140 to +142
static bool isCancelled(const Operation *self) {
return __atomic_load_n(&self->isCancelled, __ATOMIC_ACQUIRE);
}
@jdolan
jdolan merged commit de3de1b into main Oct 12, 2026
5 checks passed
@jdolan
jdolan deleted the feature/is-cancelled branch October 12, 2026 19:06
jdolan added a commit to jdolan/quetoo that referenced this pull request Oct 12, 2026
Objectively 2.4.0 makes Thread::isCancelled a method that loads the flag
atomically, so the client game's jobs no longer need the atomics builtin.

Requires Objectively 2.4.0 (jdolan/Objectively#43).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants