-
Notifications
You must be signed in to change notification settings - Fork 34
docs(fspy): document shared-memory facade ownership semantics #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+56
−18
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e0e749
docs(fspy): document shared-memory facade ownership semantics
wan9chi 1981c35
docs(fspy): describe shared memory API semantics
wan9chi 7da9688
docs(fspy): simplify shared memory API wording
wan9chi d9a54d0
docs(fspy): remove hard wraps from shared memory README
wan9chi 866b745
docs(fspy): use README for crate documentation
wan9chi 0b00f62
refactor(fspy): derive shared memory size when opening
wan9chi 61f72d8
docs(fspy): format crate name in README heading
wan9chi 2b0d301
docs(fspy): keep shared memory API description abstract
wan9chi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # `fspy_shm` | ||
|
|
||
| `fspy_shm` is the private shared-memory layer used by fspy IPC channels. It gives the channel one API for creating a mapping, passing its identifier to another process, and opening additional views of the same bytes. | ||
|
|
||
| `fspy_shm` exposes only the operations used by fspy. Callers must treat an identifier as a string and must not depend on a platform's naming scheme. | ||
|
|
||
| ## API | ||
|
|
||
| The public API is defined in [`src/lib.rs`](src/lib.rs). | ||
|
|
||
| | API | Contract | | ||
| | ----------------- | ---------------------------------------------------------------------------------- | | ||
| | `create(size)` | Creates a non-empty mapping and returns its unique owner. | | ||
| | `open(id)` | Opens another view of the mapping identified by `id`. | | ||
| | `Shm::id()` | Returns the identifier to send to another process. | | ||
| | `Shm::len()` | Returns the mapped size. | | ||
| | `Shm::as_ptr()` | Returns a mutable raw pointer to the first byte. | | ||
| | `Shm::as_slice()` | Returns a shared slice. The caller must prevent mutation for the slice's lifetime. | | ||
|
|
||
| `Shm` does not synchronize memory access. The fspy channel combines it with atomic frame headers and a lock file. Senders hold a shared file lock while writing. The receiver takes the exclusive lock before reading, which waits for existing senders and rejects new ones. | ||
|
|
||
| ## Ownership semantics | ||
|
|
||
| `create` returns the only owner. `open` returns non-owning views. | ||
|
|
||
| - While the owner is alive, a process that knows the identifier can open the mapping. | ||
| - An opened view remains usable after the owner is dropped. Its operating system mapping keeps the underlying bytes alive. | ||
| - After the owner is dropped, new opens behave differently by platform. POSIX removes the name. Windows can continue accepting opens by section name until the final handle or view is closed. | ||
|
|
||
| The channel hides that difference with its lock file. [`ChannelConf::sender`](../fspy_shared/src/ipc/channel/mod.rs) opens and locks the receiver's exact lock-file path before it calls `fspy_shm::open`. The receiver removes that path before dropping the owner, so a sender that starts later fails before opening shared memory. | ||
|
|
||
| ## Backend boundary | ||
|
|
||
| At this point in the stack, `fspy_shm` delegates mapping creation and opening to the [`shared_memory`](https://crates.io/crates/shared_memory) crate. Because callers use only the API above, later changes can replace the backend on each platform without changing the channel protocol. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows, opening without the original capacity lets
shared_memoryrecompute the opened view length from the OS mapping, which is page-rounded, while the receiver's owner still reports the requestedchannel(capacity)length. For non-page-aligned capacities, a sender can therefore use a largershm.len()forShmWriterbounds checks and advance the shared header past the receiver's slice, soReceiverLockGuard::iter_framescan panic when it slicescontent[..content_size]after enough writes. Keep the configured size inChannelConfor clamp opened views to the requested capacity.Useful? React with 👍 / 👎.