MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / AllocDesc

Method AllocDesc

src/device/virtio/virt_queue/split.hpp:298–308  ·  view source on GitHub ↗

* @brief 从空闲链表分配一个描述符 * * 从空闲描述符链表中取出一个描述符,供上层使用。 * 调用者必须填充描述符的 addr、len、flags 和 next 字段。 * * @return 成功返回描述符索引(range: 0 ~ queue_size-1); * 空闲链表为空时返回 ErrorCode::kNoFreeDescriptors * * @warning 非线程安全:多个线程同时调用可能导致竞态条件 * @see virtio-v1.2#2.7.5 The Virtqueue Descriptor Table * @see virtio-v1.2#2.7.13 Supplying Buffers to The Device */

Source from the content-addressed store, hash-verified

296 * @see virtio-v1.2#2.7.13 Supplying Buffers to The Device
297 */
298 [[nodiscard]] auto AllocDesc() -> Expected<uint16_t> {
299 if (num_free_ == 0) {
300 return std::unexpected(Error{ErrorCode::kNoFreeDescriptors});
301 }
302
303 uint16_t idx = free_head_;
304 free_head_ = desc_[free_head_].next;
305 --num_free_;
306
307 return idx;
308 }
309
310 /**
311 * @brief 归还描述符到空闲链表

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected