osync_bool osync_queue_send_message_with_timeout(OSyncQueue *queue, OSyncQueue *replyqueue, OSyncMessage *message, unsigned int timeout, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %u, %p)", __func__, queue, replyqueue, message, timeout, error); if (osync_message_get_handler(message)) { OSyncPendingMessage *pending = NULL; GTimeVal current_time; long long int id = 0; osync_assert(replyqueue); pending = osync_try_malloc0(sizeof(OSyncPendingMessage), error); if (!pending) goto error; /* g_sourcet_get_current_time used cached time ... hopefully faster then g_get_.._time() */ g_source_get_current_time(queue->timeout_source, ¤t_time); id = gen_id(¤t_time); osync_message_set_id(message, id); pending->id = id; osync_trace(TRACE_INTERNAL, "Setting id %lli for pending reply", id); if (timeout) { OSyncTimeoutInfo *toinfo = osync_try_malloc0(sizeof(OSyncTimeoutInfo), error); if (!toinfo) goto error; toinfo->expiration = current_time; toinfo->expiration.tv_sec += timeout; pending->timeout_info = toinfo; } else { osync_trace(TRACE_INTERNAL, "handler message got sent without timeout!: %s", osync_message_get_commandstr(message)); } pending->callback = osync_message_get_handler(message); pending->user_data = osync_message_get_handler_data(message); g_mutex_lock(replyqueue->pendingLock); replyqueue->pendingReplies = g_list_append(replyqueue->pendingReplies, pending); g_mutex_unlock(replyqueue->pendingLock); } osync_message_ref(message); g_async_queue_push(queue->outgoing, message); g_main_context_wakeup(queue->context); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; }
void EntityController::push_entity(Entity* entity){ //std::cout<<"EntityController::push_entity="<<entity<<std::endl; if(!entity->get_id()){ entity->set_id(gen_id()); } if(entity->get_id()>=entities.size()){ entities.resize(entities.size()+entity->get_id()+1,0); std::cout<<"EntityController::push_entity resize:"<<entities.size()<<std::endl; } entities.at(entity->get_id())=entity; }
Planet::Planet(tfloat _x, tfloat _y, tfloat _radius, int _ships_num, int _owner, int _limit, tfloat _production) : radius(_radius), ships_num(_ships_num), owner(_owner), limit(_limit), production(_production), new_ships(0) { id = gen_id(); pos = Vector(_x, _y); }