int XXp1(char *arg) { int i, result; char buffer[20]; int msgNum = 0; USLOSS_Console("\nXXp1(): started\n"); for (i = 0; i < 8; i++) { USLOSS_Console("\nXXp1(): conditionally sending message #%d ", msgNum); USLOSS_Console("to mailbox %d\n", mbox_id); sprintf(buffer, "hello there, #%d", msgNum); result = MboxCondSend(mbox_id, buffer, strlen(buffer)+1); USLOSS_Console("XXp1(): after conditional send of message "); USLOSS_Console("#%d, result = %d\n", msgNum, result); msgNum++; } MboxReceive(pause_mbox, NULL, 0); // should block on mail box for (i = 0; i < 8; i++) { USLOSS_Console("\nXXp1(): conditionally sending message #%d ", msgNum); USLOSS_Console("to mailbox %d\n", mbox_id); sprintf(buffer, "good-bye, #%d", i); result = MboxCondSend(mbox_id, buffer, strlen(buffer)+1); USLOSS_Console("XXp1(): after conditional send of message "); USLOSS_Console("#%d, result = %d\n", msgNum, result); msgNum++; } quit(-3); return 0; /* so gcc will not complain about its absence... */ } /* XXp1 */
static void terminalHandler(int dev, void *arg) { long unit = (long) arg; if (debugflag2 && DEBUG2) { USLOSS_Console("terminalHandler(): dev = %d\n", dev); USLOSS_Console("terminalHandler(): unit = %d\n", unit); } int termResult; // check for valid values if (dev != USLOSS_TERM_DEV || unit < 0 || unit > USLOSS_TERM_UNITS) { USLOSS_Console("termHandler(): Bad values\n"); USLOSS_Halt(1); } // make sure our box still exists if (termBoxes[unit].mboxID == -1) { USLOSS_Console("Term mailbox does not exist, unit\n"); USLOSS_Halt(1); // might need to reutn instead } int result = USLOSS_DeviceInput(USLOSS_TERM_DEV, unit, &termResult); // if (debugflag2 && DEBUG2) { // USLOSS_Console("terminalHandler(): sending now from dev %d to mbox %d value %s\n", dev, termBoxes[unit].mboxID, termResult); // } MboxCondSend(termBoxes[unit].mboxID, &termResult, sizeof(termResult)); if (result != USLOSS_DEV_OK) { USLOSS_Console("termHandler(): USLOSS_DeviceInput is not ok.\n"); USLOSS_Halt(1); } }
static void clockHandler2(int dev, void *arg) { long unit = (long) arg; int clockResult; // check if dispatcher should be called if (readCurStartTime() >= 80000) { timeSlice(); } // inc that a clock interrupt happened clockTicks++; USLOSS_DeviceInput(dev, unit, &clockResult); // every fith interrupt do a conditional send to its mailbox if (clockTicks % 5 == 0) { if (debugflag2 && DEBUG2) { USLOSS_Console("clockHandler2: sending message %s to mbox %d\n", clockResult, clockBox.mboxID); } int sendResult = MboxCondSend(clockBox.mboxID, &clockResult, sizeof(clockResult)); if (debugflag2 && DEBUG2) { USLOSS_Console("clockHandler2: send returned %d\n", sendResult); USLOSS_Halt(1); } } }
void termHandler(int dev, void* unit) { if (DEBUG2 && debugflag2) USLOSS_Console("termHandler(): called\n"); int status =0; USLOSS_DeviceInput(dev, (int) unit, &status); MboxCondSend(1 + (int) unit, &status, 0); } /* termHandler */
void clockHandler2(int dev, void* unit) { if (DEBUG2 && debugflag2) USLOSS_Console("clockHandler2(): called\n"); static int i = 1; if (i++ > 4){ i = 0; MboxCondSend(0, 0, 0); } timeSlice(); } /* clockHandler */
int start2(char *arg) { int kid_status, kidpid, pausepid; int result; char buffer[]="hello"; USLOSS_Console("start2(): started\n"); mbox_id = MboxCreate(0, 50); USLOSS_Console("\nstart2(): MboxCreate returned id = %d\n", mbox_id); kidpid = fork1("XXp2a", XXp2, "XXp2a", 2 * USLOSS_MIN_STACK, 3); kidpid = fork1("XXp2b", XXp2, "XXp2b", 2 * USLOSS_MIN_STACK, 3); kidpid = fork1("XXp2c", XXp2, "XXp2c", 2 * USLOSS_MIN_STACK, 3); pausepid = fork1("XXp4", XXp4, "XXp4", 2 * USLOSS_MIN_STACK, 3); kidpid = join(&kid_status); if (kidpid != pausepid) USLOSS_Console("\n***Test Failed*** -- join with pausepid failed!\n\n"); kidpid = fork1("XXp3", XXp3, NULL, 2 * USLOSS_MIN_STACK, 2); kidpid = join(&kid_status); USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n", kidpid, kid_status); kidpid = join(&kid_status); USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n", kidpid, kid_status); kidpid = join(&kid_status); USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n", kidpid, kid_status); kidpid = join(&kid_status); USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n", kidpid, kid_status); result = MboxCondSend(mbox_id, buffer, strlen(buffer)+1); if(result == -1) USLOSS_Console("failed to send to released mailbox ... success\n"); else USLOSS_Console("test failed result = %d\n",result); quit(0); return 0; /* so gcc will not complain about its absence... */ } /* start2 */
static void diskHandler(int dev, void *arg) { long unit = (long) arg; int diskResult; // check for valid values if (dev != USLOSS_DISK_DEV || unit < 0 || unit > USLOSS_DISK_UNITS) { USLOSS_Console("diskHandler(): Bad values\n"); USLOSS_Halt(1); } // make sure our box still exists if (diskBoxes[unit].mboxID == -1) { USLOSS_Console("Disk mailbox does not exist, unit = %d\n", unit); USLOSS_Halt(1); // might need to reutn instead } USLOSS_DeviceInput(USLOSS_DISK_DEV, unit, &diskResult); MboxCondSend(diskBoxes[unit].mboxID, &diskResult, sizeof(diskResult)); }