- pipe_mutex_lock(mgr->mutex);
-
- buf = NULL;
- curr = mgr->delayed.next;
- next = curr->next;
-
- /* search in the expired buffers, freeing them in the process */
- now = os_time_get();
- while(curr != &mgr->delayed) {
- curr_buf = LIST_ENTRY(struct pb_cache_buffer, curr, head);
- if(!buf && (ret = pb_cache_is_buffer_compat(curr_buf, size, desc) > 0))
- buf = curr_buf;
- else if(os_time_timeout(curr_buf->start, curr_buf->end, now))
- _pb_cache_buffer_destroy(curr_buf);
- else
- /* This buffer (and all hereafter) are still hot in cache */
- break;
- if (ret == -1)
- break;
- curr = next;
- next = curr->next;
- }
-
- /* keep searching in the hot buffers */
- if(!buf && ret != -1) {
- while(curr != &mgr->delayed) {
- curr_buf = LIST_ENTRY(struct pb_cache_buffer, curr, head);
- ret = pb_cache_is_buffer_compat(curr_buf, size, desc);
- if (ret > 0) {
- buf = curr_buf;
- break;
- }
- if (ret == -1)
- break;
- /* no need to check the timeout here */
- curr = next;
- next = curr->next;
- }
- }
-
- if(buf) {
- LIST_DEL(&buf->head);
- --mgr->numDelayed;
- pipe_mutex_unlock(mgr->mutex);
- /* Increase refcount */
- pipe_reference_init(&buf->base.base.reference, 1);
+ /* get a buffer from the cache */
+ buf = (struct pb_cache_buffer *)
+ pb_cache_reclaim_buffer(&mgr->cache, size, desc->alignment,
+ desc->usage);
+ if (buf)