VLink  2.3.0
A high-performance communication middleware
fast_buffer_manager.h 文件参考

Process-wide provider loader and shared-resource lifetime manager. 更多...

#include <memory>
#include "./fast_buffer_plugin_interface.h"
fast_buffer_manager.h 的引用(Include)关系图:

浏览源代码.

类

class  vlink::FastBufferManager
 Loads one FastBufferPluginInterface on first use. 更多...
 

命名空间

 
 

详细描述

Process-wide provider loader and shared-resource lifetime manager.

FastBufferManager owns the provider shared by every zerocopy::FastBuffer in the process. Construction of the first buffer resolves the provider through this singleton; nodes and CLI tools use the same selection without vendor SDK dependencies in VLink. The manager owns local references and one cross-process control block per exported allocation; buffers without sharing descriptors allocate no IPC state.

First-use environment Provider Manager state
Unset or empty Built-in ordinary CPU memory Valid
shm Built-in shared CPU memory Valid
Compatible plugin name or path Loaded plugin Valid
Missing or incompatible plugin None Invalid
Manager state machine
first get()
|
v
read VLINK_FASTBUFFER_PLUGIN
/ \
unset/empty/shm name/path
| |
v v
CPU implementation Plugin::load()
| / \
| valid failed
v v v
shared provider invalid
|
v
FastBuffer --> core Resource
|
local / remote references
|
SDK Buffer
|
v
release references before unloading
Holds a local memory address and an owned provider reference.
Definition: fast_buffer.h:138
Sharing control block
Each exported allocation owns one named shared-memory segment; the wire descriptor names it and carries the allocation's current generation.
Control block (shared memory) Wire descriptor (40 bytes)
+-------------------------------+ +-----------------+
| protocol / size / desc size | | name[32] |
| owner identity | | generation |
| generation (atomic) | +-----------------+
| readers[32] (atomic) |
+-------------------------------+
| provider native descriptor |
+-------------------------------+
A process identity is its PID combined with the kernel start time, so a reused PID never impersonates a dead process. On Linux the block also records the owner's PID and time namespaces, because start times are reported relative to the reader's time namespace: a process in another namespace cannot judge liveness, so its imports fail and its sweeps skip the allocation. Each importing process claims one readers slot per allocation; further imports in that process share the local resource and only raise its local reference count. An import that attaches a new mapping fails when the reader table is full or the owner process is dead; the importer then removes the dead owner's control segment and asks the provider to destroy the native resource it names. Re-imports served by a local resource only raise its reference count. On Linux and QNX, manager construction also sweeps control segments of the same protocol left behind by dead owners; other protocols are left for a process of their own provider.
Generation handshake
Reclaiming an allocation for reuse (zerocopy::FastBufferPool) or retiring it increments generation before the owner inspects readers; an importer claims its slot before comparing generation with the descriptor. Both sides use sequentially consistent operations so that at least one observes the other: the owner sees the claim and reports the allocation busy, or the importer sees the newer generation and fails as expired. In-process importers instead compare the generation and raise the local reference count under the registry mutex, which the owner also holds while checking that count. An importer that re-exports uses the generation it imported under, so a retired allocation never becomes importable again. Reclaiming also synchronizes the provider so local device work of released readers completes before the slot is handed out. An expired import drops the message exactly like a queue overflow, so a publisher never needs an import acknowledgement.
Lifetime without waiting
Final owner release retires the allocation: the generation is incremented, dead readers are purged by identity, and the provider resource is freed immediately when no live reader remains. Otherwise the allocation joins a retired list that later create or release calls reclaim; no call ever waits for another process. Retired allocations still imported by live processes at manager shutdown are logged and released anyway, which is what process exit would do moments later; importers keep the mappings they already hold where the platform allows it.
Locks
The registry mutex protects lookup, ownership changes and the retired list. Native import and close of one name, and the first export of one allocation, are serialized by lock stripes outside the registry mutex. Non-final local release is a lock-free reference decrement.

Resolution happens once. Changing the environment after the first get() has no effect; an explicit load failure does not select another provider. The manager owns the provider; returned pointers are borrowed. Release buffers before manager shutdown, as with the recording plugin manager.

Example
if (manager.is_valid()) {
auto* provider = manager.get_interface();
VLOG_I("FastBuffer protocol: ", provider->get_protocol_id());
}
#define VLOG_I(...)
Definition: logger.h:900