int scheduler_new_local_mail_N(proc_t *proc, term_t msg) { // marshalling done by the caller int x = msg_queue_push_N(&proc->mailbox, msg); if (x < 0) return x; if (proc->my_queue == MY_QUEUE_NONE) return 0; if (proc->my_queue == MY_QUEUE_NORMAL || proc->my_queue == MY_QUEUE_HIGH || proc->my_queue == MY_QUEUE_LOW) return 0; if (proc->my_queue == MY_QUEUE_TIMED_WAIT) wait_list_remove(&queues.on_timed_receive, proc); else { assert(proc->my_queue == MY_QUEUE_INF_WAIT); proc_list_remove(&queues.on_infinite_receive, proc); } proc->my_queue = MY_QUEUE_NONE; return scheduler_park_runnable_N(proc); }
void scheduler_dequeue_process(proc_t *proc) { if (proc->my_queue == MY_QUEUE_NONE) return; if (proc->my_queue == MY_QUEUE_NORMAL) proc_queue_remove(&queues.normal_prio, proc); else if (proc->my_queue == MY_QUEUE_HIGH) proc_queue_remove(&queues.high_prio, proc); else if (proc->my_queue == MY_QUEUE_LOW) proc_queue_remove(&queues.low_prio, proc); else if (proc->my_queue == MY_QUEUE_TIMED_WAIT) wait_list_remove(&queues.on_timed_receive, proc); else { assert(proc->my_queue == MY_QUEUE_INF_WAIT); proc_list_remove(&queues.on_infinite_receive, proc); } proc->my_queue = MY_QUEUE_NONE; }
/*thread que recebe da camada de baixo*/ PRIVATE void *internalsend(void *param) { int isfragmentable; int mtu; uint16_t count_id = 0; wait_list_item_t intern_list_cons; offsetlst_t *head = NULL,*aux; datagram_t *data_send = ALLOC(datagram_t, sizeof(datagram_t)); byte *buffer; while(TRUE) { intern_list_cons = wait_list_remove(); //getmtu do destino mtu = getmtu(num_global, intern_list_cons.first_dest_link); //protocolo = 1 utilizado pelo transp ou protocolo = 0 utilizado pela tab de rotas if(intern_list_cons.protocol == 1 || intern_list_cons.protocol == 0) { isfragmentable = fragpack(&head,intern_list_cons.data,intern_list_cons.size,mtu,intern_list_cons.offset); LOG("dest1 %d", intern_list_cons.dest); //sabe que é apenas dados if(isfragmentable == 0) { //nao precisou fragmentar data_send->size = intern_list_cons.size; data_send->id = count_id; data_send->frag = intern_list_cons.offset; data_send->protocol = intern_list_cons.protocol; data_send->ttl = intern_list_cons.ttl; data_send->dest = intern_list_cons.dest; data_send->src = intern_list_cons.src; data_send->data = ALLOC(byte, data_send->size); memcpy(data_send->data, intern_list_cons.data, data_send->size); buffer = ALLOC(byte, data_send->size + NET_HEADER_SIZE); buildsenddatagram(buffer,data_send); free(data_send->data); if(count_id <= 65535) count_id++; else count_id = 0; LOG("enviando para enlace"); link_send(intern_list_cons.first_dest_link, buffer, data_send->size + NET_HEADER_SIZE); //free(data_send); ??? } else {LOG("frag para enlace"); while(head != NULL) {LOG("head para enlace"); //precisa fragmentar data_send->size = head->datagram->size; data_send->id = count_id; data_send->frag = head->datagram->frag; data_send->protocol = intern_list_cons.protocol; data_send->ttl = intern_list_cons.ttl; data_send->dest = intern_list_cons.dest; LOG("dest %d", data_send->dest); data_send->src = intern_list_cons.src; data_send->data = ALLOC(byte, head->datagram->size); memcpy(data_send->data, head->datagram->data, head->datagram->size); LOG("enviando data %s", data_send->data); buffer = ALLOC(byte, data_send->size + NET_HEADER_SIZE); buildsenddatagram(buffer,data_send); free(data_send->data); link_send(intern_list_cons.first_dest_link, buffer, data_send->size + NET_HEADER_SIZE); //anda com a lista aux = head; head = head->next; free(aux); } LOG("fim para enlace"); if(count_id <= 65535) count_id++; else count_id = 0; } } //protocolo = 2 , utilizado pelo repasse else { if(intern_list_cons.protocol == 2) { isfragmentable = fragpack2(&head,intern_list_cons.data,intern_list_cons.size,mtu,intern_list_cons.offset); if(isfragmentable == 0) { //nao precisou fragmentar data_send->size = intern_list_cons.size; data_send->id = intern_list_cons.id; data_send->frag = intern_list_cons.offset; data_send->protocol = intern_list_cons.protocol; data_send->ttl = intern_list_cons.ttl; data_send->dest = intern_list_cons.dest; data_send->src = intern_list_cons.src; data_send->data = ALLOC(byte, data_send->size); memcpy(data_send->data, intern_list_cons.data, data_send->size); buffer = ALLOC(byte, data_send->size + NET_HEADER_SIZE); buildsenddatagram(buffer,data_send); free(data_send->data); LOG("enviando para enlace"); link_send(intern_list_cons.first_dest_link, buffer, data_send->size + NET_HEADER_SIZE); //free(data_send); ??? } else { while(head != NULL) { //precisa fragmentar data_send->size = head->datagram->size; data_send->id = intern_list_cons.id; data_send->frag = head->datagram->frag; data_send->protocol = intern_list_cons.protocol; data_send->ttl = intern_list_cons.ttl; data_send->dest = intern_list_cons.dest; data_send->src = intern_list_cons.src; data_send->data = ALLOC(byte, head->datagram->size); memcpy(data_send->data, head->datagram->data, head->datagram->size); buffer = ALLOC(byte, data_send->size + NET_HEADER_SIZE); buildsenddatagram(buffer,data_send); free(data_send->data); link_send(intern_list_cons.first_dest_link, buffer, data_send->size + NET_HEADER_SIZE); //anda com a lista aux = head; head = head->next; free(aux); } } } } } }