Пример #1
0
// 递增分配id进行hash,并返回匹配的socket
static int
reserve_id(struct socket_server *ss) {
	int i;
	for (i=0;i<MAX_SOCKET;i++) {
		// 递增
		int id = ATOM_INC(&(ss->alloc_id));
		if (id < 0) {
			// 回绕
			id = ATOM_AND(&(ss->alloc_id), 0x7fffffff);
		}
		// 哈希匹配
		struct socket *s = &ss->slot[HASH_ID(id)];
		if (s->type == SOCKET_TYPE_INVALID) {
			// 如果是初始类型,修改为保留类型
			if (ATOM_CAS(&s->type, SOCKET_TYPE_INVALID, SOCKET_TYPE_RESERVE)) {
				s->id = id;
				s->fd = -1;
				return id;
			} else {
				// 否则,重试
				// retry
				--i;
			}
		}
	}
	return -1;
}
Пример #2
0
void 
skynet_monitor_trigger(struct skynet_monitor *sm, uint32_t source, uint32_t destination) {
	// 在发送消息前, 记录一次状态
	sm->source = source;
	sm->destination = destination;
	ATOM_INC(&sm->version);
}
Пример #3
0
inline static void 
update_xmalloc_stat_alloc(uint32_t handle, size_t __n) {
	ATOM_ADD(&_used_memory, __n);
	ATOM_INC(&_memory_block); 
	ssize_t* allocated = get_allocated_field(handle);
	if(allocated) {
		ATOM_ADD(allocated, __n);
	}
}