예제 #1
0
파일: odp_thread.c 프로젝트: leitao/odp
int odp_thread_init_local(odp_thread_type_t type)
{
	int id;
	int cpu;

	odp_spinlock_lock(&thread_globals->lock);
	id = alloc_id(type);
	odp_spinlock_unlock(&thread_globals->lock);

	if (id < 0) {
		ODP_ERR("Too many threads\n");
		return -1;
	}

	cpu = sched_getcpu();

	if (cpu < 0) {
		ODP_ERR("getcpu failed\n");
		return -1;
	}

	thread_globals->thr[id].thr  = id;
	thread_globals->thr[id].cpu  = cpu;
	thread_globals->thr[id].type = type;

	this_thread = &thread_globals->thr[id];
	return 0;
}
예제 #2
0
std::pair<neighbor_map::iterator, bool> neighbor_map::insert(const value_type& x)
{
	if ((int)container_.size()>=maxPeerCnt_)
		return std::make_pair(end(), false);

	std::pair<iterator, bool> rst=container_.insert(x);
	if (rst.second)
		alloc_id(rst.first);
	return rst;
}
예제 #3
0
std::pair<neighbor_map::iterator, bool> neighbor_map::insert(
	const const_iterator& hint, const value_type& x)
{
	if ((int)container_.size()>=maxPeerCnt_)
		return std::make_pair(end(), false);

	size_t orgSize=container_.size();
	iterator rst=container_.insert(hint, x);
	bool ok=container_.size()>orgSize;
	if (ok)alloc_id(rst);
	return std::make_pair(rst, ok);
}
예제 #4
0
address_t
skynet_service_create(struct skynet_service *self) {
	assert_launcher(self);
	address_t id = alloc_id();
	if (id == 0)
		return 0;
	struct service_node *sn = &G->s[id % MAX_SERVICE];
	sn->svc = skynet_service_new(id);
	sn->exit = 0;
	sn->id = id;
	assert(sn->ref == 0);
	return id;
}
예제 #5
0
	uintptr_t id_generator::add_val(uintptr_t val)
	{
		uintptr_t id = alloc_id();
		id_list[id] = val;
		return id;
	}