class VmoPool
Defined at line 54 of file ../../zircon/system/ulib/fzl/include/lib/fzl/vmo-pool.h
This class is not thread safe.
VmoPool is intended to be used by content producers who have the following
usage pattern regarding a collection of VMOs:
Setup: A producer and at least one consumer establish a connection and share a
homogenous set of VMOs. A common way to do this is through BufferCollections
and the Sysmem library.
During normal operation:
1) The producer obtains a write lock on a free vmo.
2) The producer writes into the VMO. Multiple write-locked VMOs may be held
simultaneously.
3) When the producer is finished writing to the VMO, it signals the consumer
that the VMO is ready to be consumed. The VMO is now read-locked.
4) When the VMO is finished being consumed, the consumer signals the producer
that it is done with the vmo. The producer then marks that VMO as free.
VmoPool maintains the bookkeeping for the above interaction, as follows:
1) The producer calls LockBufferForWrite(), which returns a Buffer object.
2) The valid Buffer object represents a write lock.
3) When the producer is done writing, it calls ReleaseWriteLockAndGetIndex
which returns the index of the buffer. This index can be sent to the
consumer to signal that a buffer is ready to be consumed. Calling
ReleaseWriteLockAndGetIndex invalidates the Buffer object and constitutes
a read lock on the VMO.
4) When the VMO is finished being consumed, the consumer send the index back
to the producer, who then calls ReleaseBuffer on that index, marking the
VMO as free.
VmoPool additionally handles the mapping and pinning of VMOs through the
MapVmos and PinVmos functions. After the buffers have been mapped/pinned,
the virtual/physical address can be accessed through the Buffer instances.
Public Methods
size_t total_buffers ()
Returns the total number of buffers in this pool.
Defined at line 94 of file ../../zircon/system/ulib/fzl/include/lib/fzl/vmo-pool.h
size_t free_buffers ()
Returns the number of free buffers in this pool.
Defined at line 97 of file ../../zircon/system/ulib/fzl/include/lib/fzl/vmo-pool.h
size_t buffer_size (uint32_t buffer_index)
Returns the size (in bytes) of the buffer at a given index in this pool.
Defined at line 100 of file ../../zircon/system/ulib/fzl/include/lib/fzl/vmo-pool.h
zx_status_t Init (cpp20::span<zx::unowned_vmo> vmos)
Initializes the VmoPool with a set of vmos.
Defined at line 118 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
zx_status_t PinVmos (const zx::bti & bti, RequireContig req_contiguous, RequireLowMem req_low_memory)
Pin all the vmos to physical memory. This must be called prior to
requesting a physical address from any Buffer instance.
Defined at line 148 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
zx_status_t MapVmos ()
Map the vmos to virtual memory. This must be called prior to
requesting a virtual address from any Buffer instance.
Defined at line 161 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
void Reset ()
Resets the buffer read and write locks.
Defined at line 173 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
std::optional<Buffer> LockBufferForWrite ()
The only function which should construct a Buffer from an index and
a pool is VmoPool::LockBufferForWrite.
Defined at line 181 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
zx_status_t ReleaseBuffer (uint32_t buffer_index)
Unlocks the buffer with the specified index and sets it as ready to be
reused. Calling ReleaseBuffer with the index from
buffer.ReleaseWriteLockAndGetIndex() is equivalent to calling
buffer.Release().
Returns ZX_OK if successful, or ZX_ERR_NOT_FOUND if no locked buffer
was found with the given index. If the index is out of bounds,
ZX_ERROR_INVALID_ARGS will be returned.
Defined at line 192 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
void ~VmoPool ()
Defined at line 82 of file ../../zircon/system/ulib/fzl/vmo-pool.cc
Enumerations
enum RequireContig
| Name | Value |
|---|---|
| No | false |
| Yes | 1 |
Options for pinning VMOs:
Require contiguous memory:
Defined at line 58 of file ../../zircon/system/ulib/fzl/include/lib/fzl/vmo-pool.h
enum RequireLowMem
| Name | Value |
|---|---|
| No | false |
| Yes | 1 |
Require that the physical memory address be expressable as a 32bit
unsigned integer:
Defined at line 61 of file ../../zircon/system/ulib/fzl/include/lib/fzl/vmo-pool.h
Records
Friends
class Buffer