Ejemplo n.º 1
0
void wakeup(PCB *p){
 /*   printk("%d\n", list_size(&ready));*/
	if(!list_exist(&ready, &p->list)) {
		if(list_exist(&block, &p->list)) {
			list_del(&p->list);
			list_add_after(&ready, &p->list);
		}
	}
}
Ejemplo n.º 2
0
/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));
	
	struct thread *holder= lock->holder;
	
	/* If the current lock is already locked, then we update the mx_priority, by comparing it
	 * with the current_thread.
	 * We check if the thread holding the lock has less priority than the current priority so it
	 * donates it priority, then we add the current lock to the list of the thread of the donating_locks. */
	if(holder != NULL){
		if(lock->mx_priority < thread_current()->priority){
			lock->mx_priority= thread_current()->priority;
		}
		
		if(thread_current()->priority > holder->priority){
			if(!list_exist(&holder->donating_locks, &lock->elem)){
				list_push_back(&holder->donating_locks, &lock->elem);
			}
			holder->priority= thread_current()->priority;
		}
		
		thread_current()->blocked=lock;
		nest_donation(holder);
	}
	else{
		list_push_back(&thread_current()->donating_locks, &lock->elem);
	}
	
  sema_down (&lock->semaphore);
  lock->holder = thread_current();
}
Ejemplo n.º 3
0
static void
receiver(struct simple_udp_connection *c,
         const uip_ipaddr_t *sender_addr,
         uint16_t sender_port,
         const uip_ipaddr_t *receiver_addr,
         uint16_t receiver_port,
         const uint8_t *data,
         uint16_t datalen)
{
  int i,num_neigh;
  uint8_t *ptr;
  struct ip_list_struct *s;
  uip_ipaddr_t *addr;
  uip_ds6_addr_t * nh;

  // Check if this is the first time I get a message from this node
  if( !list_exist(sender_addr) ){
     // First message from this neighbour
     s = memb_alloc(&ip_mem);
     uip_ipaddr_copy(&s->ip, sender_addr);
     list_add(ip_list, s);
     printf("Neighbour added \n"); 
  }

  printf("Neighbour information received from ");
  uip_debug_ipaddr_print(sender_addr);
  printf("\n");
 
  num_neigh = datalen/sizeof(uip_ipaddr_t);
  ptr=data;
  printf("2nd hop neighbour list is: \n");
  for(i=0; i < num_neigh; i++){
     ptr += i*sizeof(uip_ipaddr_t);
     addr = ptr;
     uip_debug_ipaddr_print(addr);

     // Add the 2nd neighbors in the routing table

     if(uip_ds6_is_my_addr(addr))
        continue; // Hey this is myself

     if( list_exist(addr) )
	continue; // Hey you're a 1st hop neighbour

     // I can add the entry in the routing table
     uip_ds6_route_add(addr, 128, sender_addr);
     printf("\nAdded route\n");

     // Verify!
     nh = uip_ds6_route_lookup(addr);
     if( nh != NULL ){
        printf("TO=");
        uip_debug_ipaddr_print(addr);
        printf(" NEXTHOP=");
        uip_debug_ipaddr_print(nh); 	
     }
  }
  printf("\n");



}