/*! * Return the \c chunk at the beginning of the \c linked_list_chunk. * The \c chunk is removed from the \c linked_list_chunk. * * \param llc \c linked_list_chunk to pop from * \return The removed \c chunk at the beginning or \c NULL if linked_list_chunk empty */ chunk linked_list_chunk_pop_front ( linked_list_chunk llc ) { assert(llc != NULL); if(linked_list_chunk_is_empty(llc)) { return NULL; } chunk ch = chunk_copy(llc->first->value); inner_linked_chunk* buffILC; buffILC = llc->first; if(llc->first == llc->last) { llc->last = NULL; llc->first = NULL; buffILC->precedent = NULL; chunk_destroy(buffILC->value); buffILC->value = NULL; buffILC->suivant = NULL; free(buffILC); buffILC = NULL; } else { llc->first = llc->first->suivant; llc->first->precedent = NULL; chunk_destroy(buffILC->value); buffILC->value = NULL; buffILC->suivant = NULL; free(buffILC); buffILC = NULL; } return ch; }
/*! * Build in initial \c linked_list_chunk and then do various list modifications. * Everything is destroyed in the end. */ int main ( void ) { chunk ch ; linked_list_chunk llc = linked_list_chunk_create () ; assert ( linked_list_chunk_is_empty ( llc ) ) ; test_llc_ch ( llc , value_error_create ( 0 ) ) ; test_llc_ch ( llc , value_error_create ( 1 ) ) ; test_llc_ch ( llc , value_error_create ( 2 ) ) ; test_llc_ch ( llc , value_error_create ( 3 ) ) ; test_llc_ch ( llc , value_error_create ( 4 ) ) ; test_llc_ch ( llc , value_error_create ( 5 ) ) ; linked_list_chunk llc_2 = linked_list_chunk_copy ( llc ) ; linked_list_chunk_destroy ( llc ); puts ( " copy" ) ; linked_list_chunk_print ( llc_2 , stdout ) ; linked_list_chunk llc_3 = linked_list_chunk_copy ( llc_2 ) ; while ( ! linked_list_chunk_is_empty ( llc_2 ) ) { chunk ch = linked_list_chunk_pop_front ( llc_2 ) ; fprintf ( stdout , "*** removing from front : \"" ) ; chunk_print ( ch , stdout ) ; fprintf ( stdout , "\" :\n" ) ; linked_list_chunk_print ( llc_2 , stdout ) ; chunk_destroy ( ch ) ; } linked_list_chunk_destroy ( llc_2 ); fprintf ( stdout , "*** Adding a copy of 3 first elements: \n" ) ; linked_list_chunk_add_self_copy_front ( llc_3 , 3 ) ; linked_list_chunk_print ( llc_3 , stdout ) ; linked_list_chunk_destroy ( llc_3 ); return 0 ; }
static void deinit_trash_buffers_per_thread() { chunk_destroy(&trash); free(trash_buf2); free(trash_buf1); trash_buf2 = NULL; trash_buf1 = NULL; }
/*! * \file * \brief Operator \c def: add an entry into the \c dictionary. * * The entry is composed of a protected label on the top of the stack and the value under it. * Both values are removed from the stack. * Nothing else is modified. * * If the stack is not deep enough or the first one is not a \c value_protected_label, a \c basic_type_error is returned. * * assert is enforced. * * \author Jérôme DURAND-LOSE * \version 1 * \date 2015 * \copyright GNU Public License. */ static basic_type operator_def_evaluate ( chunk const ch , va_list va ) { interpretation_context ic = va_arg( va , interpretation_context); chunk ch1 = linked_list_chunk_pop_front(ic->stack); chunk ch2 = linked_list_chunk_pop_front(ic-> stack); if(!(ch1) || !(ch2)){ return basic_type_error; } if(value_is_protected_label(ch1)){ dictionary_set(ic->dic , basic_type_get_pointer(chunk_answer_message(ch1 , "value_get_value")) , ch2); chunk_destroy(ch1); chunk_destroy(ch2); return basic_type_void; } chunk_destroy(ch1); chunk_destroy(ch2); return basic_type_error; }
void allocator_destroy(allocator_t *allocator) { while(!dllist_is_empty(&allocator->chunks)) { dllist_link *l = dllist_rem_head(&allocator->chunks); chunk_t *tmp = DLLIST_ELEMENT(l, chunk_t, link); chunk_destroy(tmp); free(tmp); } pthread_mutex_destroy(&allocator->lock); }
static void chunk_list_destroy(chunk_list_t* list) { chunk_t* chunk; while(chunk_list_is_empty(list) == 1) { chunk = chunk_list_head(list); chunk = chunk_list_remove(list, chunk); chunk_destroy(chunk); } free(list); }
static void allocator_free(allocator_t* allocator, int heap_offset) { chunk_t* chunk_cur; chunk_t* chunk_prev; chunk_t* chunk_next; int page_offset; if(allocator == NULL) return; page_offset = heap_offset / AV_PAGE_SIZE; chunk_cur = chunk_list_head(allocator->list); while(chunk_cur != NULL) { if(chunk_cur->page_offset == page_offset) { if(chunk_cur->is_free) { logw("chunk is already free."); } chunk_cur->is_free = 1; do { chunk_prev = chunk_cur->prev; chunk_next = chunk_cur->next; if(chunk_prev != NULL && (chunk_prev->is_free == 1 || chunk_prev->page_num == 0)) { chunk_prev->page_num += chunk_cur->page_num; chunk_list_remove(allocator->list, chunk_cur); chunk_destroy(chunk_cur); } chunk_cur = chunk_next; }while(chunk_cur != NULL && chunk_cur->is_free == 1); break; } chunk_cur = chunk_cur->next; } return; }
/*! * Destroy the whole structure and the stored values. * * \param llc \c linked_list_chunk to destroy * \pre \c llc is valid (assert-ed) */ void linked_list_chunk_destroy ( linked_list_chunk llc ) { inner_linked_chunk* buffILC; while(llc->first != NULL) { buffILC = llc->first; llc->first = llc->first->suivant; buffILC->precedent = NULL; chunk_destroy(buffILC->value); buffILC->value = NULL; buffILC->suivant = NULL; free(buffILC); buffILC = NULL; } llc->first = NULL; llc->last = NULL; free(llc); llc = NULL; }
int ldt_record_destroy(ldt_record *lrecord) { if (!lrecord) { return -1; } as_rec *h_urec = lrecord->h_urec; // Note: destroy of udf_record today is no-op because all the closing // of record happens after UDF has executed. for (uint64_t i = 0; i < lrecord->max_chunks; i++) { ldt_slot_chunk *lchunk = &lrecord->chunk[i]; chunk_destroy(lrecord, lchunk); } if (lrecord->max_chunks) { // Free up allocated chunks cf_free(lrecord->chunk); } // Dir destroy should release partition reservation and // namespace reservation. udf_record_destroy(h_urec); return 0; }
uint32_t allocator_shrink(allocator_t *allocator) { uint32_t count = 0; dllist rem_list; dllist_init(&rem_list); pthread_mutex_lock(&allocator->lock); dllist_link *l = allocator->chunks.head; for (; l ;) { chunk_t *tmp = DLLIST_ELEMENT(l, chunk_t, link); dllist_link *nl = l->next; if (chunk_get_count(tmp) == tmp->nr_blocks) { allocator->chunks_count--; dllist_rem(&allocator->chunks, l); if (allocator->alloc_chunk == l) { allocator->alloc_chunk = allocator->chunks.head; } dllist_iat(&rem_list, l); count += tmp->nr_blocks; } l = nl; } pthread_mutex_unlock(&allocator->lock); while (!dllist_is_empty(&rem_list)) { dllist_link *head = dllist_rem_head(&rem_list); chunk_t *tmp = DLLIST_ELEMENT(head, chunk_t, link); chunk_destroy(tmp); free(tmp); } return count; }