diff options
Diffstat (limited to 'src/svm')
-rw-r--r-- | src/svm/fifo_segment.c | 29 | ||||
-rw-r--r-- | src/svm/fifo_segment.h | 9 | ||||
-rw-r--r-- | src/svm/svm_fifo.c | 5 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c index 9c332d6f1fa..0263d1a57cc 100644 --- a/src/svm/fifo_segment.c +++ b/src/svm/fifo_segment.c @@ -570,6 +570,35 @@ fifo_segment_grow_fifo (fifo_segment_t * fs, svm_fifo_t * f, u32 chunk_size) return 0; } +int +fifo_segment_collect_fifo_chunks (fifo_segment_t * fs, svm_fifo_t * f) +{ + svm_fifo_chunk_t *cur, *next; + ssvm_shared_header_t *sh; + void *oldheap; + int fl_index; + + sh = fs->ssvm.sh; + ssvm_lock_non_recursive (sh, 1); + + oldheap = ssvm_push_heap (sh); + cur = svm_fifo_collect_chunks (f); + + while (cur) + { + next = cur->next; + fl_index = fs_free_list_for_size (cur->length); + cur->next = fs->h->free_chunks[fl_index]; + fs->h->free_chunks[fl_index] = cur; + cur = next; + } + + ssvm_pop_heap (oldheap); + ssvm_unlock_non_recursive (sh); + + return 0; +} + /** * Get number of active fifos */ diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h index 6ff538fcc07..bb4f4080502 100644 --- a/src/svm/fifo_segment.h +++ b/src/svm/fifo_segment.h @@ -128,6 +128,15 @@ void fifo_segment_preallocate_fifo_pairs (fifo_segment_t * fs, */ int fifo_segment_grow_fifo (fifo_segment_t * fs, svm_fifo_t * f, u32 chunk_size); + +/** + * Collect unused chunks for fifo + * + * @param fs fifo segment for fifo + * @param f fifo whose chunks are to be collected + * @return 0 on success, error otherwise + */ +int fifo_segment_collect_fifo_chunks (fifo_segment_t * fs, svm_fifo_t * f); u8 fifo_segment_has_fifos (fifo_segment_t * fs); svm_fifo_t *fifo_segment_get_fifo_list (fifo_segment_t * fs); u32 fifo_segment_num_fifos (fifo_segment_t * fs); diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index e017b619d15..3824d998866 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -677,7 +677,10 @@ svm_fifo_reduce_size (svm_fifo_t * f, u32 len, u8 try_shrink) svm_fifo_chunk_t *cur; u32 actual_len = 0; - if (len > f->nitems) + /* Abort if trying to reduce by more than fifo size or if + * fifo is undergoing resizing already */ + if (len >= f->size || f->size > f->nitems + 1 + || (f->flags & SVM_FIFO_F_SHRINK) || (f->flags & SVM_FIFO_F_GROW)) return 0; /* last chunk that will not be removed */ |