int _ioreq_enqueue(Drive *d, Fd *fd, Uint8 rd, Iostate state){ Status status; Key key; Iorequest *req; if( (status = _q_remove( free_req_q, (void **) &req ))!= SUCCESS ) { _kpanic( "_ioreq_enqueue", "No free requests. Status: %s", status ); } key.v =(void *) d; req->d=d; req->fd=fd; req->read=rd; req->st=state; if (state == WAIT_ON_IDLE){ status = _q_insert( idle_q,(void *) req, key); }else if (state == WAIT_ON_DATA){ status = _q_insert( data_q,(void *) req, key); }else{ //drop invalid request status=FAILURE; } if( status != SUCCESS ) { _kpanic( "_ioreq_enqueue", "IO queue insertion status %s", status ); } return 1; }
void _dispatch( void ) { int i; Status status; // select a process from the highest-priority // ready queue that is not empty for( i = 0; i < N_READYQ; ++i ) { do { if( _q_empty(_ready[i]) ) { break; } // found one - make it the currently-running process status = _q_remove( _ready[i], (void **) &_current ); if( status == SUCCESS ) { // check to see if it needs to be cleaned up if( _current->state == KILLED ) { // yes - deallocate it _cleanup( _current ); // go back and re-check this queue continue; } _current->state = RUNNING; _current->quantum = STD_QUANTUM; return; } else { _kpanic( "_dispatch", "readyq deque status %s", status ); } } while( 1 ); } _kpanic( "_dispatch", "no non-empty readyq", EMPTY_QUEUE ); }
status_t _q_remove_by_key( queue_t *queue, void **data, key_t key ) { qnode_t *qnode; status_t stat; // verify that our parameters are usable if( queue == NULL || data == NULL ) { return( E_BAD_PARAM ); } // if the queue is empty, nothing to do if( _q_empty(queue) ) { return( E_EMPTY ); } // if there is no specialized removal routine, do an ordinary remove if( queue->remove == NULL ) { return( _q_remove(queue,data) ); } // // Traverse the queue, looking for the correct element. // Use the built-in removal routine to determine when // we have found the correct entry. // qnode = queue->head; while( qnode != NULL && !queue->remove(qnode->key,key) ) { qnode = qnode->next; } // did we find the one we wanted? if( qnode == NULL ) { return( E_NOT_FOUND ); } // found the correct node - unlink it from the queue if( qnode->prev != NULL ) { qnode->prev->next = qnode->next; } else { queue->head = qnode->next; } if( qnode->next != NULL ) { qnode->next->prev = qnode->prev; } else { queue->tail = qnode->prev; } queue->length -= 1; // return the data from the node *data = qnode->data; // release the qnode // // INCONSISTENCY: _q_remove() just propogates the status stat = _qnode_free( qnode ); if( stat != E_SUCCESS ) { _kpanic( "_q_remove_by_key", "qnode free failed, %s", stat ); } return( E_SUCCESS ); }