示例#1
0
文件: luniq.c 项目: rocaltair/luniq
static int lua__uniq_new_id(lua_State *L)
{
	struct handlemap * h = CHECK_UNIQ(L, 1);
	handleid id = handlemap_new(h, HANDLE_UD_NULL);
	lua_pushinteger(L, id);
	return 1;
}
static THREAD_FUNC
create(void *p) {
	struct handlemap *m = p;
	int i;
	for (i=0;i<HANDLE_N;i++) {
		pool[i] = handlemap_new(m, (void *)((intptr_t)i+1));
		printf("create %d id=%u\n",i,pool[i]);
		usleep(50);
		int r = rand() % (i+1);
		handleid id = pool[r];
		void *ptr = handlemap_release(m, id);
		if (ptr) {
			printf("release %d, id = %u, ptr = %p\n", r, id, ptr);
		} else {
			printf("release %d failed, id= %u\n", r,id);
		}
	}
	for (i=0;i<HANDLE_N;i++) {
		handleid id = pool[i];
		void *ptr = handlemap_release(m, id);
		if (ptr) {
			printf("clear %d, id = %u, ptr = %p\n", i, id, ptr);
		}
	}
	return 0;
}