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;
}
Exemplo n.º 2
0
static int lua__uniq_release(lua_State *L)
{
	struct handlemap * h = CHECK_UNIQ(L, 1);
	handleid id = (handleid)luaL_checkinteger(L, 2);
	handlemap_release(h, id);
	return 0;
}
static void
grab(struct handlemap *m, int thread) {
	int i;
	for (i=0;i<HANDLE_N;i++) {
		int r = rand() % (i+1);
		handleid id = pool[r];
		void *ptr = handlemap_grab(m, id);
		printf("thread %d: grab %d, id = %u, ptr = %p\n", thread, r, id, ptr);
		usleep(50);
		if (ptr) {
			ptr = handlemap_release(m, id);
			if (ptr) {
				printf("thread %d: release %d, id = %u, ptr = %p\n", thread, r, id, ptr);
			}
		}
	}
}