コード例 #1
0
ファイル: myalloc.c プロジェクト: NinerLP/OS-2012
static void free_bucket(bucket* buck) {
	if (buck == NULL) {
		return;
	}
	free_bucket(buck->next);
	munmap((void *) buck,sizeof(bucket)+buck->len);
}
コード例 #2
0
ファイル: myalloc.c プロジェクト: NinerLP/OS-2012
void free(void * ptr) {
	if (ptr == NULL) {
		return;
	}
	pthread_mutex_lock(&thread_list_mutex);
	localthread* lt = get_localthread(pthread_self());
	pthread_mutex_unlock(&thread_list_mutex);
	if (lt == NULL) {
		return;
	}
	//we get realsize that was calculated
	size_t * size_ptr = ((size_t *) ptr) - sizeof(size_t);
	size_t realsize = *size_ptr;
	if (realsize < MIN_SIZE) {
		//lin
		bucket* buck = (bucket*) (ptr-sizeof(bucket));
		pthread_mutex_lock(&(lt->small_bucket_mutex));
		if (bucket_list_size(lt->small_list) < SML_LIMIT) {
			buck->next = lt->small_list;
			lt->small_list = buck;
			buck = NULL;
		}
		pthread_mutex_unlock(&(lt->small_bucket_mutex));
		if (buck) {
			free_bucket(buck);
		}
	} else if (realsize < MAX_SIZE) {
		//heap thingy free blahblah
	} else {
		//dumbfree
		munmap((void *) size_ptr, *size_ptr);
	}	
}
コード例 #3
0
ファイル: hashmap.c プロジェクト: arendsee/c-practice
void free_bucket(struct bucket * b){
    if(b){
        if(b->next)        
            free_bucket(b->next);
        free(b);
    }
}
コード例 #4
0
ファイル: HashIdx.cpp プロジェクト: mbsky/tcache
void HashIdx::release_node(VElt *bucket)
{
	if (bucket-> blink != NULL)
		bucket->blink->flink = bucket->flink;
	if (bucket -> flink != NULL)
		bucket -> flink -> blink = bucket -> blink;
	free_bucket (bucket);
}
コード例 #5
0
ファイル: myalloc.c プロジェクト: NinerLP/OS-2012
static void free_localthread(localthread* lt) {
	if (lt == NULL) {
		return;
	}
	free_bucket(lt->small_list);
	pthread_mutex_destroy(&(lt->small_bucket_mutex));
	free_localthread(lt->next);
	munmap((void *)lt, sizeof(localthread));
}
コード例 #6
0
ファイル: pandb.c プロジェクト: Cue/Pincaster
static void free_bucket_node(BucketNode * const bucket_node)
{
    if (bucket_node == NULL) {
        return;
    }
    free_bucket(&bucket_node->bucket);
    bucket_node->type = NODE_TYPE_NONE;
    bucket_node->parent = NULL;
    free(bucket_node);
}
コード例 #7
0
ファイル: genhash.c プロジェクト: couchbase/moxi
static void
free_bucket(genhash_t* h, struct genhash_entry_t* b)
{
    if(b != NULL) {
        free_bucket(h, b->next);
        h->ops.freeKey(b->key);
        h->ops.freeValue(b->value);
        free(b);
    }
}
コード例 #8
0
ファイル: chains_remove.c プロジェクト: iksaif/ikmalloc
void
chunk_remove_free(struct malloc_infos *list, struct chunk *chunk)
{
  int i;

  i = free_bucket(chunk->size);
  LIST_REMOVE(list->lfree[i], chunk, free);
  list->lfree_cnt[i]--;
  chunk->type = MALLOC_CHUNK_USED;
}
コード例 #9
0
ファイル: genhash.c プロジェクト: couchbase/moxi
void
genhash_free(genhash_t* h)
{
    if(h != NULL) {
        size_t i=0;
        for(i=0; i<h->size; i++) {
            free_bucket(h, h->buckets[i]);
        }
        free(h);
    }
}
コード例 #10
0
ファイル: chains_append.c プロジェクト: iksaif/ikmalloc
void
chunk_append_free(struct malloc_infos *list, struct chunk *chunk)
{
  int i;

  i = free_bucket(chunk->size);
  LIST_APPEND(list->lfree[i], chunk, free);
  list->lfree_cnt[i]++;
  chunk->type = MALLOC_CHUNK_FREE;
  chunk->asked_size = 0;
}
コード例 #11
0
ファイル: shash.c プロジェクト: hongwozai/emms
void Shash_free(T *hash)
{
    assert(hash);
    /* 注意还要释放桶内节点 */
    int i;
    for (i = 0; i < hash->len; ++i) {
        free_bucket(&hash->buckets[i]);
    }
    FREE(hash->buckets);
    FREE(hash);
}
コード例 #12
0
ファイル: hashmap.c プロジェクト: goodpaul6/generic
void map_clear(hashmap_t* map)
{
	for(size_t i = 0; i < map->active_buckets.length; ++i)
	{
		unsigned long pos = *(unsigned long*)vec_get(&map->active_buckets, i);
		hashmap_node_t* node = map->buckets[pos];
		free_bucket(node);
		map->buckets[pos] = NULL;
	}
	
	vec_clear(&map->active_buckets);
}
コード例 #13
0
ファイル: hashmap.c プロジェクト: arendsee/c-practice
void free_hashmap(struct hashmap * map){
    if(map){
        if(map->table){
            for(int i = 0; i < map->index_size; i++){
                if(map->table[i])
                    free_bucket(map->table[i]);
            }
            free(map->table);
        }
        free(map);
    }
}
コード例 #14
0
static void free_bucket_entries(hash_table *table){
    int i;
    bucket *element_to_delete, *t_item;
    for (i=0; i< table->size; i++){
        t_item = table->table[i];
        while(t_item) {
            element_to_delete = t_item;
            t_item = t_item->next;
            free_bucket(element_to_delete);
        }
        
    }
}
コード例 #15
0
static void free_buckets(__cilkrts_worker  *w, 
                         bucket           **buckets,
                         size_t             nbuckets)
{
    size_t i;

#if REDPAR_DEBUG >= 1
    verify_current_wkr(w);
    fprintf(stderr, "W=%d, desc=free_buckets, buckets=%p, size=%zd\n",
	    w->self, buckets,
	    nbuckets * sizeof(*buckets));
#endif

    for (i = 0; i < nbuckets; ++i)
        free_bucket(w, buckets + i);

    __cilkrts_frame_free(w, buckets, nbuckets * sizeof(*buckets));
}
コード例 #16
0
/* grow bucket by one element, reallocating bucket if necessary */
elem *cilkred_map::grow(__cilkrts_worker *w, 
                        bucket          **bp)
{
    size_t i, nmax, nnmax;
    bucket *b, *nb;

    b = *bp;
    if (b) {
        nmax = b->nmax;
        /* find empty element if any */
        for (i = 0; i < nmax; ++i) 
            if (b->el[i].key == 0) 
                return &(b->el[i]);
        /* do not use the last one even if empty */
    } else {
        nmax = 0;
    }

    verify_current_wkr(w);
    /* allocate a new bucket */
    nnmax = roundup(2 * nmax);
    nb = alloc_bucket(w, nnmax);


    /* copy old bucket into new */
    for (i = 0; i < nmax; ++i)
        nb->el[i] = b->el[i];
     
    free_bucket(w, bp); *bp = nb;

    /* zero out extra elements */
    for (; i < nnmax; ++i)
        nb->el[i].key = 0;

    /* zero out the last one */
    nb->el[i].key = 0;
  
    return &(nb->el[nmax]);
}