| 560 | } |
| 561 | |
| 562 | int ProgramManager::wait(int *retval) |
| 563 | { |
| 564 | PCB *child; |
| 565 | ListItem *item; |
| 566 | bool interrupt, flag; |
| 567 | |
| 568 | while (true) |
| 569 | { |
| 570 | interrupt = interruptManager.getInterruptStatus(); |
| 571 | interruptManager.disableInterrupt(); |
| 572 | |
| 573 | item = this->allPrograms.head.next; |
| 574 | |
| 575 | flag = true; |
| 576 | while (item) |
| 577 | { |
| 578 | child = ListItem2PCB(item, tagInAllList); |
| 579 | if (child->parentPid == this->running->pid) |
| 580 | { |
| 581 | flag = false; |
| 582 | if (child->status == ProgramStatus::DEAD) |
| 583 | { |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | item = item->next; |
| 588 | } |
| 589 | |
| 590 | if (item) |
| 591 | { |
| 592 | if (retval) |
| 593 | { |
| 594 | *retval = child->retValue; |
| 595 | } |
| 596 | |
| 597 | int pid = child->pid; |
| 598 | this->allPrograms.erase(&(child->tagInAllList)); |
| 599 | interruptManager.setInterruptStatus(interrupt); |
| 600 | return pid; |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | if (flag) |
| 605 | { |
| 606 | |
| 607 | interruptManager.setInterruptStatus(interrupt); |
| 608 | return -1; |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | interruptManager.setInterruptStatus(interrupt); |
| 613 | schedule(); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | } |
no test coverage detected