void *buffer_thread(){ PID pid; PacketDescriptor p1; while(1){ p1 = blockingReadBB(buffer); pid = packet_descriptor_get_pid(&p1); blockingWriteBB(incoming[pid], p1); } return NULL; }
void blocking_read_sector(SectorDescriptor sd, Voucher *v) { struct voucher* vouch = (struct voucher*) malloc(sizeof(struct voucher)); vouch->sector = sd; vouch->status = -1; vouch->type = READ_REQ; pthread_mutex_init(&(vouch->voucherMutex), NULL); pthread_cond_init(&(vouch->voucherCond), NULL); *v = (Voucher) vouch; blockingWriteBB(readVoucherBuffer, *v); }
//the 4 methods for read/write are very similar, so i only comment this one void blocking_write_sector(SectorDescriptor sd, Voucher *v) { struct Voucher* vouch = (struct Voucher*) malloc(sizeof(struct Voucher)); //create a new voucher vouch->sector = sd; //initialise with sd that will be read/written vouch->status = -1; //initial status flag vouch->type = WRITE; //its of type write pthread_mutex_init(&(vouch->vouchMut), NULL); //initiate mutex pthread_cond_init(&(vouch->vouchCond), NULL); //initate condition variable *v = (Voucher) vouch; //return the created voucher inside v provided blockingWriteBB(writeBuffer, *v); //does a blocking add to the write buffer }
void blocking_read_sector(SectorDescriptor sd, Voucher *v) { struct Voucher* vouch = (struct Voucher*) malloc(sizeof(struct Voucher)); pthread_mutex_init(&(vouch->vouchMut), NULL); pthread_cond_init(&(vouch->vouchCond), NULL); vouch->sector = sd; vouch->status = -1; vouch->type = READ; *v = (Voucher) vouch; blockingWriteBB(readBuffer, *v); //does a blocking add to the read buffer }
void blocking_send_packet(PacketDescriptor pd){//a way for applications to queue up their packets to be sent blockingWriteBB(outgoing, pd); return; }