コード例 #1
0
ファイル: ewx_hash_table.c プロジェクト: zliu/libewx
ewx_hash_table_t *ewx_hash_table_init(char *name, int bucket_num, int bucket_size, int item_size, int auto_lock)
{
	int i;

	bucket_size = align(bucket_size, 128);

	if ((bucket_size != 128) && (bucket_size != 256)) {
		return NULL;
	}

	ewx_hash_table_t *ptr = cvmx_bootmem_alloc_named((uint64_t)(bucket_num) * bucket_size + sizeof(ewx_hash_table_t), 128, name);
	if (ptr == NULL) {
		return NULL;
	}
	memset(ptr, 0, (uint64_t)bucket_num * bucket_size + sizeof(ewx_hash_table_t));

	strcpy(ptr->name, name);

	ptr->bucket_num = bucket_num;
	ptr->bucket_size = bucket_size;
	ptr->item_size = item_size;
	ptr->item_num = (bucket_size - sizeof(ewx_bucket_hd_t))/item_size;
	ptr->base_ptr = (void *)ptr + sizeof(ewx_hash_table_t);

	if (auto_lock) {
		char lock_name[30];
		strcpy(lock_name, name);
		strcat(lock_name, LOCK_SUFFIX);
		ptr->lock = cvmx_bootmem_alloc_named(sizeof(cvmx_spinlock_t) * (uint64_t)bucket_num, 128, lock_name);
		if (ptr->lock == NULL) {
			/*释放hash表空间,返回NULL*/
			cvmx_bootmem_free_named(name);
			return NULL;
		}
		for (i=0; i<bucket_num; i++) {
			cvmx_spinlock_init(&ptr->lock[i]);
		}
	} else {
		ptr->lock = NULL;
	}
	return ptr;
}
コード例 #2
0
void oct_rxtx_Release()
{
    int rc;
    rc = cvmx_bootmem_free_named(OCT_TX_DESC_NAME);
    printf("%s free rc=%d\n", OCT_TX_DESC_NAME, rc);
}