Ejemplo n.º 1
0
void *buffer_thread(){
	PID pid;
	PacketDescriptor p1;
	while(1){
		p1 = blockingReadBB(buffer);
		pid = packet_descriptor_get_pid(&p1);
		blockingWriteBB(incoming[pid], p1);
	}
	return NULL;
}
Ejemplo n.º 2
0
static void* writeThreadRun(void* args) {
    while(1) {
        struct voucher* v = (struct voucher*) blockingReadBB(readVoucherBuffer);
        int status = write_sector(diskDevice, &(v->sector));
        pthread_mutex_lock(&(v->voucherMutex));
        v->status = status;
        pthread_cond_signal(&(v->voucherCond));
        pthread_mutex_unlock(&(v->voucherMutex));
    }
    pthread_exit(NULL);
}
Ejemplo n.º 3
0
void *sending_thread(){
	int i;
	PacketDescriptor pd;
	int r; 
	int sleep; 
	while (1){
		pd = blockingReadBB(outgoing);
		for (i=0;i<10;i++){
			if ((send_packet(netdev, pd)) == 1){
				break;			
			}
			r=random();
			sleep = (unsigned int) r; //casting to unsigned removes any negative numbers
			sleep = sleep % powers(2,i); // limits it to the desired range//
			usleep(sleep); //I believe this code is waiting a random time in the range 0-(2 to the power i) microseconds	
		}
		blocking_put_pd(fpds, pd);
	}
	return NULL;
}
Ejemplo n.º 4
0
/* Neither call should delay until the packet is actually sent      */
void blocking_get_packet(PacketDescriptor* pd, PID pid){ // a way for applications to definitely get packets from their respective "cubbyholes" 
	*pd = blockingReadBB(incoming[pid]);
	return;
}