* @brief 归还描述符到空闲链表 * * 将不再使用的描述符放回空闲链表,供后续分配使用。 * 对于描述符链,调用者必须按正确的顺序释放链中的每个描述符。 * * @param idx 要释放的描述符索引(必须为之前分配的有效索引) * * @warning 非线程安全:多个线程同时调用可能导致竞态条件 * @warning 释放已释放的描述符或无效索引会导致空闲链表损坏 * @see virtio-v1.2#2.7.14 Receiving Used Buffers From The Device */
| 320 | * @see virtio-v1.2#2.7.14 Receiving Used Buffers From The Device |
| 321 | */ |
| 322 | auto FreeDesc(uint16_t idx) -> Expected<void> { |
| 323 | if (idx >= queue_size_) { |
| 324 | return std::unexpected(Error{ErrorCode::kInvalidDescriptor}); |
| 325 | } |
| 326 | desc_[idx].next = free_head_; |
| 327 | free_head_ = idx; |
| 328 | ++num_free_; |
| 329 | return {}; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * @brief 获取描述符的可变引用 |
nothing calls this directly
no outgoing calls
no test coverage detected