Beispiel #1
0
int main(void){
	Pilha my_stack;
	fila my_queue;
	iniciar_stack(tamanho,&my_stack);
	iniciar_queue(tamanho,&my_queue);
	
	for(register unsigned int cont = 0 ; cont < 10 ; cont ++){
		push_queue(cont,&my_queue);
		printf("Fila(%d):%d\n",cont+1,cont);
	}
	int *aux;
	aux = (int*)malloc((sizeof(tamanho)));
	aux = listar_queue(my_queue);
	for(register unsigned int cont = 0 ; cont < 10 ; cont ++){
		int valor = aux[cont];
		push_stack(valor,&my_stack);
		printf("Fila(%d):%d\n",cont+1,aux[cont]);
		pop_queue(&my_queue);
	}
	int quantidade;
	aux = listar_stack(my_stack,&quantidade);
	for(register unsigned int cont = 0 ; cont < 10 ; cont ++){
		int valor = aux[cont];
		push_queue(valor,&my_queue);
		printf("Fila(%d):%d\n",cont+1,aux[cont]);
	}
	free(aux);
}
Beispiel #2
0
int map_client_with_webserver(int wbSock, int clSock) {
	LOG_INFO("Consumer: Map_Client_With_Webserver\n");
	int res;
	
	if (contains_appropriate_clients(wbSock) != FOUND) {
		Queue queue;	
		init_queue(&queue);
		
		if (push_queue(&queue, &clSock) != OK) {
			return QUEUE_ERROR;
		}
		
		pthread_mutex_lock(&wb_cl_map_mutex);	
		res = put_hashmap(&wb_cl_map, &wbSock, sizeof(int), &queue, sizeof(Queue));
		pthread_mutex_unlock(&wb_cl_map_mutex);
	} else {
		Queue *queue = find_appropriate_clients(wbSock);
		
		pthread_mutex_lock(&wb_cl_map_mutex);	
		res = push_queue(queue, &clSock);
		pthread_mutex_unlock(&wb_cl_map_mutex);
	}
	
	return res;
}
Beispiel #3
0
void 
post_rest_read(struct net_service* service, struct net_session* session)
{
	void* data;
	struct read_session* rsession;
	size_t size;
	int err;
	int msgcnt;

	rsession = session->rsession;
	if(!rsession) return ;
	rsession->etflag = 0;

	for (;;)
	{
		size = recv_buff_prepare(rsession->rbuff, &data);
		if (size == 0)
		{
			rsession->etflag = 1;
			break;
		}
		err = recv(session->fd, (char*)data, (int)size, 0);
		msgcnt = recv_buff_consume(rsession->rbuff, err < 0? 0 : (size_t)err);
		if (err > 0)
		{
			if(msgcnt > 0)
			{
				push_queue(service, session, Eve_Read);
			}
			else if(msgcnt < 0)
			{
				// error happend
				print_error();
				clean_epoll_op(service, session);
				push_queue(service, session, Handle_socket_consume_error | Eve_Error);
				return;
			}
		}
		else if (err == 0)
		{
			// socket closed
			print_error();
			clean_epoll_op(service, session);
			push_queue(service, session, Handle_socket_close | Eve_Error);
			break;
		}
		else
		{
			err = net_get_error();
			if (err != EAGAIN )
			{
				print_error();
				clean_epoll_op(service, session);
				push_queue(service, session, Handle_get_error | Eve_Error);
			}
			break;
		}
	}
}
Beispiel #4
0
TEAM *input_dat(FILE *fp, int *num_team)
{
	char line[SIZE_STR], **token;
	int i, num_token;
	int cmp_pts();
	TEAM team_home, team_away, *team_ary;
	struct list *team_list, *p;

	*num_team = 0;
	team_list = init_list();
	while (fgets(line, SIZE_STR, fp) != NULL) {
		if (line[0] != '#') {
			token = tokenize_str(line, "-\t\n", &num_token);
			if (num_token >= 4) {
				set_home_team(&team_home, token);
				set_away_team(&team_away, token);

				if ((p = search_team(team_list, team_home.name)) == NULL) {
					push_queue(team_list, &team_home, sizeof(team_home));
					(*num_team)++;
				}
				else {
					add_team_result(p, team_home);
				}

				if ((p = search_team(team_list, team_away.name)) == NULL) {
					push_queue(team_list, &team_away, sizeof(team_away));
					(*num_team)++;
				}
				else {
					add_team_result(p, team_away);
				}
			}
			free_token_ary(token, num_token);
		}
	}

	team_ary = (TEAM *) malloc(sizeof(TEAM) * (*num_team));
	if (team_ary == NULL) {
		fprintf(stderr, "ERROR: Unable to allocate memory.\n");
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < *num_team; i++) {
		pop_queue(team_list, &team_ary[i], sizeof(TEAM));
	}
	delete_list(team_list);

	/* 安定ソートで被ゴール数→ゴール数→得失点差→勝ち点の順で整列すると順位で並ぶ */
	/* リーグ戦の規程によってはこのやり方ではダメ */
	bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_gag);
	bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_gfo);
	bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_gdi);
	bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_pts);

	return team_ary;
}
int main(int ac, char **av)
{
  Queue *queue;
  int i;
  char *str;

  queue = NULL;
  i = 0;
  while (i < ac)
    {
      push_queue(&queue, av[i]);
      ++i;
    }
  print_queue(queue);
  str = pop_queue(&queue);
  printf("%s\n", str);
  print_queue(queue);
  str = pop_queue(&queue);
  printf("%s\n", str);
  print_queue(queue);
  str = pop_queue(&queue);
  printf("%s\n", str);
  print_queue(queue);
  return (0);
}
Beispiel #6
0
void UART0_IRQHandler(void)
{
    int iir;
    iir = U0IIR;

    switch (iir & UIIR_ID_MASK) {
        case UIIR_THRE_INT:               // Transmit Holding Register Empty
            fifo = 0;
            push_queue();
            break;

        case UIIR_CTI_INT:                // Character Timeout Indicator
        case UIIR_RDA_INT:                // Receive Data Available
#ifdef MODULE_UART0
            if (uart0_handler_pid != KERNEL_PID_UNDEF) {
                do {
                    int c = U0RBR;
                    uart0_handle_incoming(c);
                }
                while (U0LSR & ULSR_RDR);

                uart0_notify_thread();
            }

#endif
            break;

        default:
            U0LSR;
            U0RBR;
            break;
    } // switch

    VICVectAddr = 0;                    // Acknowledge Interrupt
}
Beispiel #7
0
void QContentHubServer::push_queue_nowait(msgpack::rpc::request &req, const std::string &name, const std::string &obj)
{
    queue_map_t &qmap = q_map.unsafe_ref();

    queue_map_it_t it = qmap.find(name);
    if (it == qmap.end()) {
        int ret = add_queue(name, DEFAULT_QUEUE_CAPACITY);
        if (ret == QCONTENTHUB_ERROR) {
            req.result(ret);
        } else {
            push_queue(req, name, obj);
        }
    } else {
        queue_t *q = it->second;
        pthread_mutex_lock(&q->lock);
        if ((int)q->str_q.size() > q->capacity) {
            pthread_mutex_unlock(&q->lock);
            req.result(QCONTENTHUB_AGAIN);
        } else {
            q->str_q.push(obj);
            pthread_cond_signal(&q->not_empty);
            pthread_mutex_unlock(&q->lock);
            req.result(QCONTENTHUB_OK);
        }
    }
}
Beispiel #8
0
void
handle_accept(struct net_service* service, int ret, int err, struct accept_session*	asession)
{
    struct net_session*	session;

    unsigned int			session_index;

//	asession = (struct accept_session*)ov_data;

    if( !asession || asession->id == 0)
    {
        release_accept_session(asession);
        return;
    }
    session_index = ffid_index(service->socket_ids, asession->id);
    net_lock(&service->session_lock[session_index]);
    session = service->sessions[session_index];

    if (!ret && err)
    {
        net_close_fd(asession->accept_socket);
        if (!session || !session->lsession || session->id != asession->id)
        {
            net_unlock(&service->session_lock[session_index]);
            push_queue_with_lock(service, asession->id, Eve_Post_Listen_Error);
            release_accept_session(asession);
            return;
        }
    }
    else
    {
        if (!session || !session->lsession || session->id != asession->id)
        {
            net_unlock(&service->session_lock[session_index]);
            push_queue_with_lock(service, asession->id, Eve_Post_Listen_Error);
            release_accept_session(asession);
            return;
        }
        if (!push_queue(service, session, Eve_Accept))
        {
            net_close_fd(asession->accept_socket);
        }
        else if (msg_buff_write(session->lsession->socket_queue, (void*)&asession->accept_socket) != 1)
        {
            net_close_fd(asession->accept_socket);
        }
        else
        {
            setsockopt(asession->accept_socket, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char*)&session->fd, sizeof(session->fd));
        }
    }

    net_unlock(&service->session_lock[session_index]);
    asession->accept_socket = 0;
    if(post_listen(service, session, asession))
    {
        release_accept_session(asession);
        push_queue_with_lock(service, session->id, Eve_Post_Listen_Error);
    }
}
Beispiel #9
0
void
handle_write(struct net_service* service, int ret, int err, struct write_session* wsession, size_t bytes)
{
    struct net_session* session;
    unsigned short index;
    unsigned int events;
    ffid_vtype fd;

    if(!wsession)
    {
        return;
    }
    fd = wsession->id;
    if(fd == 0)
    {
        release_write_session(wsession);
        return;
    }

    index = ffid_index(service->socket_ids, fd);
    net_lock(&service->session_lock[index]);
    session = service->sessions[index];
    wsession->op = OP_NET_NONE;
    if(ret && bytes >= 0)
    {
        send_buff_consume(wsession->sbuff, bytes);
    }

    if(!session || session->id != fd)
    {
        if(ret && wsession->send_rest && post_rest_write(service, wsession) > 0)
        {
            net_unlock(&service->session_lock[index]);
            return;
        }
        release_write_session(wsession);
        net_unlock(&service->session_lock[index]);
        return;
    }

    ret = post_write(service, session);
    events = 0;
    if(ret < 0)
    {
        events |= Eve_Error;
        print_error();
    }

    if (!events || push_queue(service, session, events) > 0)
    {
        net_unlock(&service->session_lock[index]);
        return;
    }
    net_unlock(&service->session_lock[index]);
    net_socket_close(service, fd, 0);
}
Beispiel #10
0
/* LIFO Based queue test */
void testQ() {
	struct queue *my_queue;
	my_queue=NULL;

	my_queue=alloc_queue(my_queue);

	push_queue(my_queue,5);
	push_queue(my_queue,10);
	push_queue(my_queue,15);
	push_queue(my_queue,20);
	
	printf("Popped from queue: %d\n",pop_queue(my_queue));
	printf("Popped from queue: %d\n",pop_queue(my_queue));

	push_queue(my_queue,35);
	
	printf("Popped from queue: %d\n",pop_queue(my_queue));
	printf("Popped from queue: %d\n",pop_queue(my_queue));
}
Beispiel #11
0
void tick_beacon(void){
    static int beaconctr=0;
    if(GLOBAL(privacy)>0)
        return;

    if(beaconctr--<0){
        push_queue(&do_openbeacon);
        beaconctr=B_INTERVAL/SYSTICKSPEED/2;
        beaconctr+=getRandom()%(beaconctr*2);
    };
}
Beispiel #12
0
void
expect_push_queue_and_pop_queue_to_work_consistently() {
  Queue *q = new_queue();

  assert(push_queue(q, 1) == 0);
  assert(push_queue(q, 2) == 0);
  assert(push_queue(q, 3) == 0);
  assert(push_queue(q, 4) == 0);
  assert(push_queue(q, 5) == 0);

  assert(pop_queue(q) == 1);
  assert(pop_queue(q) == 2);
  assert(pop_queue(q) == 3);
  assert(pop_queue(q) == 4);
  assert(pop_queue(q) == 5);

  assert(pop_queue(q) == -1);

  destroy_queue(q);
}
Beispiel #13
0
vector* breadth_first_traversal(avl_tree* _Tree)
{
   queue* _Queue = create_queue();
   vector* _Vector = create_vector();

   push_queue(_Queue, (void*)_m_root);

   while (size_queue(_Queue) != 0)
   {
      avl_node* _Node = pop_queue(_Queue);

      _Vector = _Node->m_value;

      if (_Node->m_left_child != 0) push_queue(_Node->m_left_child);

      if (_Node->m_right_child != 0) push_queue(_Node->m_right_child);
   }
 
   return _Vector;
        
}
Beispiel #14
0
void stdio_flush(void)
{
    U0IER &= ~BIT1;                             // disable THRE interrupt

    while (running) {
        while (!(U0LSR & (BIT5 | BIT6))) {};    // transmit fifo

        fifo = 0;

        push_queue();                           // dequeue to fifo
    }

    U0IER |= BIT1;                              // enable THRE interrupt
}
Beispiel #15
0
static void number_connected_verts(struct mds* m, mds_id v,
    struct mds_tag* tag, mds_id* label)
{
  struct queue q;
  struct mds_set adj[2];
  int i;
  adj[0].n = adj[1].n = 0;
  if (!visit(m, tag, label, v))
    return;
  make_queue(&q, m->n[MDS_VERTEX]);
  push_queue(&q, v);
  while ( ! queue_empty(&q)) {
    v = pop_queue(&q);
    mds_get_adjacent(m, v, 1, &adj[1]);
    adj[0].n = adj[1].n;
    for (i = 0; i < adj[1].n; ++i)
      adj[0].e[i] = other_vert(m, adj[1].e[i], v);
    for (i = 0; i < adj[0].n; ++i)
      if (visit(m, tag, label, adj[0].e[i]))
        push_queue(&q, adj[0].e[i]);
  }
  free_queue(&q);
}
Beispiel #16
0
int insertSock_webservers(int sock) {
	LOG_INFO("Consumer: InsertSock to Webservers\n");
	pthread_mutex_lock(&queue_mutex);
	if (push_queue(&queue_webservers, &sock) != OK) {
		LOG_ERROR("Consumer: Unable to insert sock to Webservers\n");
		pthread_mutex_unlock(&queue_mutex);
		return CONSUMER_ERROR;
	}
	
	hasPending++;
	pthread_cond_signal(&queue_cond);
	pthread_mutex_unlock(&queue_mutex);
	
	return OK;
}
Beispiel #17
0
void tick_alive(void){
    static int foo=0;

    if(GLOBAL(alivechk)==0)
        return;

	if(foo++>500/SYSTICKSPEED){
		foo=0;
        if(GLOBAL(alivechk)==2)
            push_queue(blink_led0);
        else
            blink_led0();
	};
    return;
};
Beispiel #18
0
void
expect_queue_to_accept_many_elements(int n_elements) {
  int i;
  Queue *q = new_queue();

  for (i = 0; i < n_elements; i++) {
    assert(push_queue(q, i) == 0);
  }

  for (i = 0; i < n_elements; i++) {
    assert(pop_queue(q) == i);
  }

  destroy_queue(q);
}
int main(int ac, char **av)
{
        Queue *queue;
        int i;

        queue = NULL;
        i = 0;
        while (i < ac)
        {
                push_queue(&queue, av[i]);
                ++i;
        }
	printf("----------print----------\n");
        print_queue(queue);
        return (0);
}
Beispiel #20
0
void mesh_systick(void){
    static int rcvctr=0;
    static int sendctr=0;

    if(rcvctr--<0){
        push_queue_plus(&mesh_recvloop_plus);
        rcvctr=M_RECVINT/SYSTICKSPEED/2;
        rcvctr+=getRandom()%(rcvctr*2);
    };

    if(sendctr--<0){
        push_queue(&mesh_sendloop);
        sendctr=M_SENDINT/SYSTICKSPEED/2;
        sendctr+=getRandom()%(sendctr*2);
    };
};
Beispiel #21
0
// post a write op
int 
post_write(struct net_service* service, struct net_session* session)
{
	struct write_session* wsession;
	void* data;
	size_t size;

	if(!service)
	{
		return -1;
	}

	if(!session->wsession)
	{
		return -1;
	}
	wsession = session->wsession;
	if(wsession->op != OP_NET_NONE)
	{
		post_rest_write(service, session);
		return 0;
	}
	size = send_buff_prepare(wsession->sbuff, &data);
	if(size == 0)
	{
		return 0;
	}
	
	if(epoll_ctl_op(service->net_service_fd, session, OP_NET_WRITE))
	{
		wsession->op = OP_NET_NONE;
		print_error();
		push_queue(service, session, WriteError | Eve_Error);
		clean_epoll_op(service, session);

	}
	else
	{
		wsession->op = OP_NET_WRITE;
	}
	return 1;
}
Beispiel #22
0
void
handle_read(struct net_service* service, int ret, int err, struct read_session* rsession, size_t bytes)
{
    struct net_session* session;
    unsigned short index;
    unsigned int events;

    if(!rsession)
    {
        return;
    }

    if(rsession->id == 0)
    {
        release_read_session(rsession);
        return;
    }

    index = ffid_index(service->socket_ids, rsession->id);
    net_lock(&service->session_lock[index]);
    session = service->sessions[index];
    if(!session || session->id != rsession->id)
    {
        release_read_session(rsession);
        net_unlock(&service->session_lock[index]);
        return;
    }
    rsession->op = OP_NET_NONE;

    events = Eve_Read;
    if((!ret && err) || post_read(service, session) )
    {
        events |= Eve_Error;
        print_error();
    }
    push_queue(service, session, events);
    net_unlock(&service->session_lock[index]);
}
Beispiel #23
0
int 
// post a read op
post_read(struct net_service* service, struct net_session* session)
{
	struct read_session* rsession;

	if( !service)
	{
		return -1;
	}
	if( !session->rsession )
	{
		return -1;
	}
	rsession = session->rsession;

	if(rsession->op != OP_NET_NONE)
	{
		if(session->rsession->etflag)
		{
			post_rest_read(service, session);
		}
		return 0;
	}

	if(epoll_ctl_op(service->net_service_fd, session, OP_NET_READ))
	{
		print_error();
		push_queue(service, session, Eve_Read | Eve_Error);
		clean_epoll_op(service, session);
	}
	else
	{
		rsession->op = OP_NET_READ;
	}
	return 1;
}
Beispiel #24
0
void QContentHubServer::push_queue(msgpack::rpc::request &req, const std::string &name, const std::string &obj)
{
    queue_map_t &qmap = q_map.unsafe_ref();

    queue_map_it_t it = qmap.find(name);
    if (it == qmap.end()) {
        int ret = add_queue(name, DEFAULT_QUEUE_CAPACITY);
        if (ret == QCONTENTHUB_ERROR) {
            req.result(ret);
        } else {
            push_queue(req, name, obj);
        }
    } else {
        queue_t *q = it->second;
        pthread_mutex_lock(&q->lock);

        while ((int)q->str_q.size() > q->capacity) {
            struct timespec ts;
            clock_gettime(CLOCK_REALTIME, &ts);
            ts.tv_sec += 60;
            int rc = pthread_cond_timedwait(&q->not_full, &q->lock, &ts);
            if (rc == ETIMEDOUT) {
                pthread_mutex_unlock(&q->lock);
                req.result(QCONTENTHUB_STRAGAIN);
                return;
            } else if (rc != 0) {
                pthread_mutex_unlock(&q->lock);
                req.result(QCONTENTHUB_STRERROR);
                return;
            }
        }
        q->str_q.push(obj);
        pthread_cond_signal(&q->not_empty);
        pthread_mutex_unlock(&q->lock);
        req.result(QCONTENTHUB_OK);
    }
}
Beispiel #25
0
void QContentHubServer::dispatch(msgpack::rpc::request req) {
    try {
        std::string method;
        req.method().convert(&method);

        if(method == "push") {
            msgpack::type::tuple<std::string, std::string> params;
            req.params().convert(&params);
            push_queue(req, params.get<0>(), params.get<1>());
        } else if(method == "pop") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            pop_queue(req, params.get<0>());
        } else if(method == "push_nowait") {
            msgpack::type::tuple<std::string, std::string> params;
            req.params().convert(&params);
            push_queue_nowait(req, params.get<0>(), params.get<1>());
        } else if(method == "pop_nowait") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            pop_queue_nowait(req, params.get<0>());
        } else if(method == "add") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            add_queue(req, params.get<0>(), params.get<1>());
        /*
        } else if(method == "del") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            del_queue(req, params.get<0>());
        } else if(method == "fdel") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            force_del_queue(req, params.get<0>());
        */
        } else if(method == "set_capacity") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            set_queue_capacity(req, params.get<0>(), params.get<1>());
        } else if(method == "start") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            start_queue(req, params.get<0>());
        } else if(method == "stop") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stop_queue(req, params.get<0>());
        } else if(method == "clear") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            clear_queue(req, params.get<0>());
        } else if(method == "stats") {
            stats(req);
        } else if(method == "stat_queue") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stat_queue(req, params.get<0>());
        } else {
            req.error(msgpack::rpc::NO_METHOD_ERROR);
        }
    } catch (msgpack::type_error& e) {
        req.error(msgpack::rpc::ARGUMENT_ERROR);
        return;

    } catch (std::exception& e) {
        req.error(std::string(e.what()));
        return;
    }
}
void Ethernet0_Callback ( void *arg1, unsigned int event, void *FrameBuffers )
{
	/*
	ADI_ETHER_EVENT_FRAME_RCVD  One or more frames received.
	ADI_ETHER_EVENT_FRAME_XMIT  One or more frames tramsmitted.
	ADI_ETHER_EVENT_INTERRUPT  Ethernet event has occured.
	ADI_ETHER_EVENT_PHY_INTERRUPT  PHY interrupt has occured
	*/
	
	//ADI_ETHER_FRAME_BUFFER *pPkt;
	
	ADI_ETHER_BUFFER *pack_list = ( ADI_ETHER_BUFFER * ) FrameBuffers;

	ADI_ETHER_BUFFER *pRecv;
	

	if ( pack_list != NULL )
	{

		/* packet list may get modified from the TCP thread and all
		 * instances of it were protected using the critical regions
		 * Here we are in a critical region because we do not want to be
		 * preempted with a high priority interrupt.
		 */
		//int int_sts = cli();
		ENTER_CRITICAL_REGION();
		
		switch ( event )
		{
		
			case ADI_ETHER_EVENT_FRAME_RCVD:
			
				while ( pack_list )
				{
					pRecv = pack_list;
					
					pack_list = pack_list->pNext;
					
					pRecv->pNext = NULL;

					//Notes: 过滤其他非SV报文  by wjm@ 204-8-8
					//if ( pUChar[16] == 0x88 && pUChar[17] == 0xba )
					//Notes:只做纯粹的接收、打时标、协议转发工作,报文过滤交由上层应用处理, by wjm@2014-8-16 AM 10:21
					EnQueue ( &user_net_config_info[0].rx_completed_q, pRecv );
					
				}
				
				break;
				
			case ADI_ETHER_EVENT_FRAME_XMIT:
			
				if ( pack_list )
				{
					push_queue ( &user_net_config_info[0].xmt_queue, pack_list );
				}
				
				break;
				
			case ADI_ETHER_EVENT_INTERRUPT:
				break;
				
			case ADI_ETHER_EVENT_PHY_INTERRUPT:
				break;
		}
		
		//sti(int_sts);
		EXIT_CRITICAL_REGION();
	}
	
}
Beispiel #27
0
int main(int argc, char * argv[]) {
  try {
    indri::api::Parameters& param = indri::api::Parameters::instance();
    param.loadCommandLine( argc, argv );

    if( param.get( "version", 0 ) ) {
      std::cout << INDRI_DISTRIBUTION << std::endl;
    }

    if( !param.exists( "query" ) )
      LEMUR_THROW( LEMUR_MISSING_PARAMETER_ERROR, "Must specify at least one query." );

    if( !param.exists("index") && !param.exists("server") )
      LEMUR_THROW( LEMUR_MISSING_PARAMETER_ERROR, "Must specify a server or index to query against." );

    if (param.exists("baseline") && param.exists("rule"))
      LEMUR_THROW( LEMUR_BAD_PARAMETER_ERROR, "Smoothing rules may not be specified when running a baseline." );

    int threadCount = param.get( "threads", 1 );
    std::queue< query_t* > queries;
    std::priority_queue< query_t*, std::vector< query_t* >, query_t::greater > output;
    std::vector< QueryThread* > threads;
    indri::thread::Mutex queueLock;
    indri::thread::ConditionVariable queueEvent;

    // push all queries onto a queue
    indri::api::Parameters parameterQueries = param[ "query" ];
    int queryOffset = param.get( "queryOffset", 0 );
    push_queue( queries, parameterQueries, queryOffset );
    int queryCount = (int)queries.size();

    // launch threads
    for( int i=0; i<threadCount; i++ ) {
      threads.push_back( new QueryThread( queries, output, queueLock, queueEvent, param ) );
      threads.back()->start();
    }

    int query = 0;

    bool inexFormat = param.exists( "inex" );
    if( inexFormat ) {
      std::string participantID = param.get( "inex.participantID", "1");
      std::string runID = param.get( "runID", "indri" );
      std::string inexTask = param.get( "inex.task", "CO.Thorough" );
      std::string inexTopicPart = param.get( "inex.topicPart", "T" );
      std::string description = param.get( "inex.description", "" );
      std::string queryType = param.get("inex.query", "automatic");
      std::cout << "<inex-submission participant-id=\"" << participantID
    << "\" run-id=\"" << runID
    << "\" task=\"" << inexTask
    << "\" query=\"" << queryType
    << "\" topic-part=\"" << inexTopicPart
    << "\">" << std::endl
    << "  <description>" << std::endl << description
    << std::endl << "  </description>" << std::endl;
    }

    // acquire the lock.
    queueLock.lock();

    // process output as it appears on the queue
    while( query < queryCount ) {
      query_t* result = NULL;

      // wait for something to happen
      queueEvent.wait( queueLock );

      while( output.size() && output.top()->index == query ) {
        result = output.top();
        output.pop();

        queueLock.unlock();

        std::cout << result->text;
        delete result;
        query++;

        queueLock.lock();
      }
    }
    queueLock.unlock();

    if( inexFormat ) {
      std::cout << "</inex-submission>" << std::endl;
    }

    // join all the threads
    for( size_t i=0; i<threads.size(); i++ )
      threads[i]->join();

    // we've seen all the query output now, so we can quit
    indri::utility::delete_vector_contents( threads );
  } catch( lemur::api::Exception& e ) {
    LEMUR_ABORT(e);
  } catch( ... ) {
    std::cout << "Caught unhandled exception" << std::endl;
    return -1;
  }

  return 0;
}
Beispiel #28
0
/**
 * @name expand_node
 *
 * Create the states that are attached to this one.  Check to see that
 * each one has not already been visited.  If not add it to the priority
 * queue.
 */
void Wordrec::expand_node(FLOAT32 worst_priority,
                          CHUNKS_RECORD *chunks_record,
                          SEARCH_RECORD *the_search) {
  STATE old_state;
  int x;
  uinT32 mask = 1 << (the_search->num_joints - 1 - 32);

  old_state.part1 = the_search->this_state->part1;
  old_state.part2 = the_search->this_state->part2;

  // We need to expand the search more intelligently, or we get stuck
  // with a bad starting segmentation in a long word sequence as in CJK.
  // Expand a child node only if it is within the global bound, and no
  // worse than 2x of its parent.
  // TODO(dsl): There is some redudency here in recomputing the priority,
  // and in filtering of old_merit and worst_priority.
  the_search->this_state->part2 = old_state.part2;
  for (x = the_search->num_joints; x > 32; x--) {
    the_search->this_state->part1 = mask ^ old_state.part1;
    if (!hash_lookup (the_search->closed_states, the_search->this_state)) {
      FLOAT32 new_merit = prioritize_state(chunks_record, the_search);
      if (new_merit < worst_priority) {
        if (wordrec_debug_level > 1)
          log_state("Pushing segstate", the_search->num_joints,
                    the_search->this_state, new_merit);
        push_queue(the_search->open_states, the_search->this_state,
                   worst_priority, new_merit, wordrec_debug_level > 1);
      } else {
        if (wordrec_debug_level > 1)
          log_state("Ignore weak segstate", the_search->num_joints,
                    the_search->this_state, new_merit);
      }
    }
    mask >>= 1;
  }

  if (the_search->num_joints > 32) {
    mask = 1 << 31;
  }
  else {
    mask = 1 << (the_search->num_joints - 1);
  }

  the_search->this_state->part1 = old_state.part1;
  while (x--) {
    the_search->this_state->part2 = mask ^ old_state.part2;
    if (!hash_lookup (the_search->closed_states, the_search->this_state)) {
      FLOAT32 new_merit = prioritize_state(chunks_record, the_search);
      if (new_merit < worst_priority) {
        if (wordrec_debug_level > 1)
          log_state("Pushing segstate", the_search->num_joints,
                    the_search->this_state, new_merit);
        push_queue(the_search->open_states, the_search->this_state,
                   worst_priority, new_merit, wordrec_debug_level > 1);
      } else {
        if (wordrec_debug_level > 1)
          log_state("Ignoring weak segstate", the_search->num_joints,
                    the_search->this_state, new_merit);
      }
    }
    mask >>= 1;
  }
}
Beispiel #29
0
void
handle_session(struct net_service* service, struct net_session* session, int events)
{
	unsigned int event;
	int error;
	int err;

	error = 0;
	event = 0;

	socklen_t len = sizeof(int);

	if(!session) return;

	if(session->lsession)
	{
		error = 1;
	}

	// printf("%d %d %d %d %d %d %d\n", session->id, session->events, error, events & EPOLLERR, events & EPOLLHUP, events & EPOLLOUT, events & EPOLLIN);
	// fflush(stdout);
	if(session->lsession)
	{
		// listen session
		push_queue(service, session, Eve_Accept);
		return;
	}

	if(session->connect_flag)
	{
		event |= Eve_Connect;
	}

	if((events & EPOLLERR) || (events & EPOLLHUP))
	{
		print_error();
		clean_epoll_op(service, session);
		push_queue(service, session, event | EPOLLERR_EPOLLHUP | Eve_Error);
		return;
	}

	if(session->connect_flag)
	{
		if(events & EPOLLOUT)
		{
			if (( 0 == getsockopt(session->fd, SOL_SOCKET, SO_ERROR, &error, &len) )) {
				if( 0 == error ) {
					clean_epoll_op(service, session);
					push_queue(service, session, Eve_Connect);
					return;
				}
			}
			// maybe error
			print_error();
			clean_epoll_op(service, session);
			push_queue(service, session, Eve_Connect | Eve_Error);
		}
		return;
	}

	if(events & EPOLLOUT)
	{
		err = post_rest_write(service, session);
		// service->handle_msg_cnt += 1;
		if(err < 0)
		{
			print_error();
			clean_epoll_op(service, session);
			push_queue(service, session, Handle_EPOLLOUT | Eve_Error);
		}
		else if(err == 0)
		{
			//no have need write data
			
		}
	}

	if(events & EPOLLIN )
	{
		post_rest_read(service, session);
	}
}
void Ethernet1_Callback ( void *arg1, unsigned int event, void *FrameBuffers )
{

	ADI_ETHER_BUFFER *pack_list = ( ADI_ETHER_BUFFER * ) FrameBuffers;
	ADI_ETHER_BUFFER *pRecv, *pXmt;
	ADI_ETHER_FRAME_BUFFER * pPkt;
	
	if ( pack_list != NULL )
	{
	
		/* packet list may get modified from the TCP thread and all
		 * instances of it were protected using the critical regions
		 * Here we are in a critical region because we do not want to be
		 * preempted with a high priority interrupt.
		 */
		//int int_sts = cli();
		ENTER_CRITICAL_REGION();
		
		switch ( event )
		{
		
			case ADI_ETHER_EVENT_FRAME_RCVD:
			
				while ( pack_list )
				{
					pRecv = pack_list;
					pack_list = pack_list->pNext;
					pRecv->pNext = NULL;
					
					EnQueue ( &user_net_config_info[1].rx_completed_q, pRecv );
				}
				
				break;
				
			case ADI_ETHER_EVENT_FRAME_XMIT:
#if 0
				while ( pack_list )
				{
					pXmt = pack_list;
					pack_list = pack_list->pNext;
					pXmt->pNext = NULL;

					pPkt = ( ADI_ETHER_FRAME_BUFFER * ) ( pXmt->Data );

					// forward SMV frame to PC
					if( (pPkt->LTfield[0] == BF609_FORWARD_SMV_TYPE_LO) &&
							(pPkt->LTfield[1] == BF609_FORWARD_SMV_TYPE_HI ))
					{
						//reuse buff, return the buff to EMAC0' RX Channel
						pXmt->pNext = NULL;
						pXmt->ProcessedElementCount = 0;
						pXmt->ProcessedFlag = 0;
						adi_ether_Read ( g_hDev[0], pXmt );
					}
					// send other frame to PC controller, such as ACK frame for control messages.
					else
					{
						if( (pPkt->LTfield[0] == BF609_UPDATE_VER_ACKOK_TYPE_LO) &&
								(pPkt->LTfield[1] == BF609_UPDATE_VER_ACKOK_TYPE_HI ))
						{
							g_ACKOK_XMT_Completed = 1;
						}

						push_queue ( &user_net_config_info[1].xmt_queue, pXmt );
					}
				}
#endif
				while ( pack_list )
				{
					pXmt = pack_list;
					pack_list = pack_list->pNext;
					pXmt->pNext = NULL;

					pPkt = ( ADI_ETHER_FRAME_BUFFER * ) ( pXmt->Data );

					if( (pPkt->LTfield[0] == BF609_UPDATE_VER_ACKOK_TYPE_LO) &&
							(pPkt->LTfield[1] == BF609_UPDATE_VER_ACKOK_TYPE_HI ))
					{
						g_ACKOK_XMT_Completed = 1;
					}

					push_queue ( &user_net_config_info[1].xmt_queue, pXmt );

				}
				break;
				
			case ADI_ETHER_EVENT_INTERRUPT:
				break;
				
			case ADI_ETHER_EVENT_PHY_INTERRUPT:
				break;
		}
		
		//sti(int_sts);
		EXIT_CRITICAL_REGION();
	}
	
}