static void* writeThreadRun(void* args) { while(1) { struct Voucher* v; int readFromBufferStatus = nonblockingReadBB(writeBuffer, (void*)&v); if (readFromBufferStatus == 1){ //if readFromBufferStatus is 1, it meant the buffer wasn't empty and it had a voucher w/ sd int status = write_sector(diskDev, &(v->sector)); pthread_mutex_lock(&(v->vouchMut)); v->status = status; pthread_mutex_unlock(&(v->vouchMut));//lock so it cant be changed pthread_cond_signal(&(v->vouchCond));//unlock } //else if the buffer was empty just do nothing and loop back round } return 0; }
int nonblocking_get_packet(PacketDescriptor* pd, PID pid){ //a way for applications to attempt to get packets from their respective "cubbyholes" return nonblockingReadBB(incoming[pid], pd); }