Skip to content

Hoist semaphore ownership out of TokenExecutor#609

Open
chall37 wants to merge 1 commit into
gnachman:masterfrom
chall37:refactor/hoist-the-semaphore
Open

Hoist semaphore ownership out of TokenExecutor#609
chall37 wants to merge 1 commit into
gnachman:masterfrom
chall37:refactor/hoist-the-semaphore

Conversation

@chall37
Copy link
Copy Markdown
Contributor

@chall37 chall37 commented Mar 9, 2026

Move creation and wait-site of the backpressure semaphore from TokenExecutor into its callers: TaskNotifier (PTY read path) and PTYSession (channel/mux path).

TokenExecutor no longer owns any semaphore; it receives one via the semaphore: parameter and passes it through to TokenArray, which signals it on consumption exactly as before.

TaskNotifier creates a per-task semaphore on registration and looks it up (under tasksLock) before each read. PTYSession creates one per channel session. No semantic change intended.

As a reminder, this is the first step in flow control abstraction -- no behavioral changes are intended. Next step would be the flow control interface.

Move creation and wait-site of the backpressure semaphore from
TokenExecutor into its two callers: TaskNotifier (PTY read path) and
PTYSession (channel/mux path). TokenExecutor no longer owns any
semaphore; it receives one via the semaphore: parameter and passes it
through to TokenArray, which signals it on consumption exactly as before.

TaskNotifier creates a per-task semaphore on registration and looks it
up (under tasksLock) before each read. PTYSession creates one per
channel session. No semantic change intended.
@chall37 chall37 marked this pull request as ready for review March 9, 2026 17:46
@chall37
Copy link
Copy Markdown
Contributor Author

chall37 commented Mar 9, 2026

Looks like d518a59 broke the libsixel submodule ref (from e2c8546 to d300081). Don't see the d300081 commit in libsixel fork or upstream. Maybe local changes?

Comment thread sources/TaskNotifier.m

// Per-task backpressure semaphores, keyed by task identity.
// Created on register, removed on deregister.
NSMapTable<id<iTermTask>, dispatch_semaphore_t> *_backpressureSemaphores;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What if PTYTask owned its semaphore? Then we wouldn't need _backpressureSemaphores: in fact, TaskNotifier could remain unchanged. -[PTYTask processRead] could wait on and signal its semaphore. Another benefit of doing the wait inside processRead is that it could read before waiting, reducing latency (probably very slightly) when it is eventually unblocked.

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