int __omp_collector_api(void *arg)
{
    
  if(arg!=NULL) {
    message_queue_t pending_requests;
    char *traverse = (char *) arg;

    message_queue_init(&pending_requests);
 
    while((int)(*traverse)!=0) {
      omp_collector_message* req = message_queue_push(&pending_requests);
      req->sz = (int)(*traverse); // todo: add check for consistency    
      traverse+=sizeof(int);
      req->r = (OMP_COLLECTORAPI_REQUEST)(*traverse);  // todo: add check for a valid request
      traverse+=sizeof(int);      
      req->ec= (OMP_COLLECTORAPI_EC *) traverse;  // copy address for response of error code
      traverse+=sizeof(int);    
      req->rsz = (int *)(traverse);
      traverse+=sizeof(int);
      req->mem = traverse;
      traverse+=req->sz-(4*sizeof(int));
    } 

    while(!message_queue_empty(&pending_requests)) {
      omp_collector_message pop_req;
      message_queue_pop(&pending_requests, &pop_req);
      process_top_request(&pop_req);  
    }
    return 0;
  }
  return -1;
}
Exemple #2
0
void broadcast(Vector* threads, struct Message msg) {
    mprintf("Broadcasting message with type %d\n", msg.type);
    size_t len = getVectorSize(threads);
    for (size_t i = 0; i < len; i++) {
        struct PlaneThread* plane = (struct PlaneThread*) getFromVector(threads, i);
        if (!plane->done) {
            message_queue_push(plane->queue, msg);
        }
    }
}
Exemple #3
0
void redirect_destinations_message(Vector* threads, union MapMessage* in) {

    struct Message msg;
    struct PlaneThread* thread = (struct PlaneThread*) getFromVector(threads, in->destinations.planeId);

    msg.type = MessageTypeDestinations;
    memcpy(msg.payload.destinations.destinations, in->destinations.destinations, MAX_DESTINATIONS * sizeof(int));
    memcpy(msg.payload.destinations.distances, in->destinations.distance, MAX_DESTINATIONS * sizeof(int));
    msg.payload.destinations.count = in->destinations.count;

    message_queue_push(thread->queue, msg);
}
Exemple #4
0
void redirect_stock_message(Vector* threads, union MapMessage* in) {
    struct Message msg;
    struct PlaneThread* thread = (struct PlaneThread*) getFromVector(threads, in->stock.header.id);
    struct StockMessagePart* stock = &in->stock.stocks;

    msg.type = MessageTypeStock;
    msg.payload.stock.count = stock->count;
    memcpy(msg.payload.stock.delta, stock->quantities, sizeof(int) * MAX_STOCKS);

    mprintf("Redirect stock message to %d with stock count %d\n", thread->plane->id, stock->count);
    message_queue_push(thread->queue, msg);
}
void message_queue_example(){
	int i, x;
	struct message_queue q;
	int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	
	// initialize.
	message_queue_init(&q);
	
	// add messages.
	for(i=0;i<10;i++){
		message_queue_push(&q, &data[i]);
	}
	
	// get all of the messages.
	while(q.msg_num){
		x = *((int*)message_queue_pop(&q));
		printf("msg: %d\n", x);	
	}
	
	// destroy
	message_queue_destroy(&q);
}