コード例 #1
0
ファイル: tls.c プロジェクト: yuchao86/xdbcache
void set_tls_data(int32_t key,void *data)
{
	hash_map_t h = (hash_map_t)pthread_getspecific(thread_key);
	if(!h)
	{
		h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq);
	}
	hash_map_iter it = hash_map_find(h,(void*)&key);
	hash_map_iter end = hash_map_end(h);
	if(IT_EQ(it,end))
		HASH_MAP_INSERT(int32_t,void*,h,key,data);
	else
		IT_SET_VAL(void*,it,data);
}
コード例 #2
0
ファイル: tls.c プロジェクト: yuchao86/xdbcache
void *get_tls_data(int32_t key)
{
	hash_map_t h = (hash_map_t)pthread_getspecific(thread_key);
	if(!h)
	{
		h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq);
		return NULL;
	}	
	hash_map_iter it = hash_map_find(h,(void*)&key);
	hash_map_iter end = hash_map_end(h);
	if(!IT_EQ(it,end))
		return IT_GET_VAL(void*,it);
	return NULL;
}
コード例 #3
0
ファイル: testhash.c プロジェクト: hdczsf/kendylib
int main()
{

    hash_map_t h = hash_map_create(4096,sizeof(int32_t),sizeof(int32_t),_hash_func_,_hash_key_eq_);
    int32_t i = 1;
    for( ; i < 10; ++i)
    {
        hash_map_iter it = HASH_MAP_INSERT(int32_t,int32_t,h,i,i);
        printf("%d\n",IT_GET_VAL(int32_t,it));
    }
    printf("----------------------\n");
    {
        hash_map_iter it = HASH_MAP_FIND(int32_t,h,5);
        hash_map_iter end = hash_map_end(h);
        if(!IT_EQ(it,end))
            printf("%d\n",IT_GET_VAL(int32_t,it));
    }
    printf("----------------------\n");
    {
        hash_map_iter it = HASH_MAP_FIND(int32_t,h,100);
        hash_map_iter end = hash_map_end(h);
        if(!IT_EQ(it,end))
            printf("%d\n",IT_GET_VAL(int32_t,it));
        else
            printf("can't find 100\n");
    }
    printf("----------------------\n");
    HASH_MAP_REMOVE(int32_t,h,5);
    {
        hash_map_iter it = hash_map_begin(h);
        hash_map_iter end = hash_map_end(h);
        for( ; !IT_EQ(it,end); IT_NEXT(it))
            printf("%d\n",IT_GET_VAL(int32_t,it));
    }
    return 0;
};
コード例 #4
0
ファイル: tls.c プロジェクト: yuchao86/xdbcache
void clear_tls()
{
	if(is_init)
	{
		if(COMPARE_AND_SWAP(&is_init,1,0) == 1)
		{
			pthread_key_delete(thread_key);
			mutex_lock(tls_mtx);
			list_iter it = list_begin(tls_list);
			list_iter end = list_end(tls_list);
			for( ; !IT_EQ(it,end); IT_NEXT(it))
			{
				hash_map_t h = IT_GET_VAL(hash_map_t,it);
				hash_map_destroy(&h);
			}
			mutex_unlock(tls_mtx);
			mutex_destroy(&tls_mtx);
			list_destroy(&tls_list);
		}
	}
}