Beispiel #1
0
void block(int mboxID, int block, int size, char message[], int *realSize) {
    // get the correct process from the process table
    process *proc = &processTable[getpid() % 50];

    // add info to that process
    proc->pid = getpid();
    proc->blockStatus = block;
    proc->mboxID = mboxID;
    proc->timeAdded = USLOSS_Clock();
    proc->size = size;

    // if a zero slot message box wants to send a message
    if (message != NULL && block == SENDBLOCK) {
        memcpy(proc->message, message, size);
    }

    // actually block
    blockMe(block);

    if (message != NULL && block == RECEIVEBLOCK) {
        memcpy(message, processTable[getpid() % 50].message, size);
        *realSize = processTable[getpid() % 50].size;
    }

    if (block == RECEIVEBLOCK) {
        // empty out this slot in the processTable
        processTable[getpid() % 50].pid = -1;
        processTable[getpid() % 50].blockStatus = -1;
        processTable[getpid() % 50].message[0] = '\0';
        processTable[getpid() % 50].size = -1;
        processTable[getpid() % 50].mboxID = -1;
        processTable[getpid() % 50].timeAdded = -1;
    }
}
Beispiel #2
0
int XXp2(char *arg)
{
  int result;

  printf("XXp2(): started, pid = %d, calling blockMe\n", getpid());
  result = blockMe(11);
  printf("XXp2(): pid = %d, after blockMe, result = %d\n", getpid(), result);
  printf("XXp2(): pid = %d, isZapped() = %d\n", getpid(), isZapped());
  quit(0);
  return 0;
} /* XXp2 */