/*-----------------------------------Test 5---------------------------*/ void test5 () { int lck[5]; int index; int ret; kprintf("\nTest 5: release multiple locks simultaneously\n"); for (index = 0; index < 5; index++) { lck[index] = lcreate (); assert (lck[index] != SYSERR,"Test 5 FAILED\n"); ret = lock (lck[index], READ, DEFAULT_LOCK_PRIO); assert (ret == OK,"Test 5 FAILED\n"); } ret = releaseall (2, lck[4], lck[0]); assert (ret == OK,"Test 5 FAILED\n"); ret = releaseall (3, lck[1], lck[3], lck[2]); assert (ret == OK,"Test 5 FAILED\n"); for (index = 0; index < 5; index++) { ldelete (lck[index]); } kprintf ("Test 5 PASSED!\n"); }
void combo(char *msg, int lck1, int lck2, int lprio1, int lprio2) { int rc; // Get first lock kprintf (" %s: to acquire read lock %d\n", msg, lck1); rc = lock(lck1, READ, lprio1); if (rc == SYSERR) { kprintf (" %s: lock returned SYSERR\n", msg); return; } if (rc == DELETED) { kprintf (" %s: lock was DELETED\n", msg); return; } kprintf (" %s: acquired lock %d, sleep 3s\n", msg, lck1); // Get second lock kprintf (" %s: to acquire write lock %d\n", msg, lck2); rc = lock(lck2, WRITE, lprio2); if (rc == SYSERR) { kprintf (" %s: lock returned SYSERR\n", msg); releaseall(1, lck1); return; } if (rc == DELETED) { kprintf (" %s: lock was DELETED\n", msg); releaseall(1, lck1); return; } kprintf (" %s: acquired lock %d, sleep 3s\n", msg, lck2); sleep (3); kprintf (" %s: to release locks\n", msg); releaseall(2, lck1, lck2); }
void writer4 (char *msg, int lck) { lock (lck, WRITE, DEFAULT_LOCK_PRIO); sleep (5); releaseall (1, lck); }
void getAllLocks(char c, int *lockArr, int lockType, int prio, int setupTime, int holdTime){ int i,j=0,retval; while(1) { sleep(setupTime); for(i=0; i<NLOCKS; i++) { // printf("%c %d %d %d %d %d\n",c,lockArr[0],lockArr[1],lockArr[2],lockArr[3],lockArr[4]); retval = lock(lockArr[i], lockType, prio); if(retval != OK) { kprintf("StressTest op-%d: %c%c%c%c%c Lock %d failed : %d\n",lockType,c,c,c,c,c, lockArr[i], retval); return; } } // kprintf("%c%c%c%c%c\n",c,c,c,c,c); for(i=0; i<holdTime*10; i++) { kprintf("StressTest op-%d: %c%c%c%c%c\n",lockType,c,c,c,c,c); sleep1000(50); } for(i=0; i<NLOCKS; i+=2 ) { retval = releaseall(2, lockArr[i], lockArr[i+1]); if(retval != OK) { kprintf("StressTest op-%d: %c%c%c%c%c Release %d failed : %d\n",lockType,c,c,c,c,c,lockArr[i],retval); return; } } j++; if(j == 10) break; } }
int retryingWriter(char c, int ldes1, int prio) { int flag; flag = lock(ldes1, WRITE, prio); if(flag == SYSERR) { kprintf("\n%c's lock returned SYSERR!", c); return; } if(flag == DELETED) { kprintf("\n%c's lock was deleted!", c); kprintf("\n%c trying to acquire lock %d again!", c, ldes1); flag = lock(ldes1, WRITE, prio); if(flag == SYSERR) { kprintf("\n%c's lock returned SYSERR!", c); return; } return; } kprintf("\n%c has obtained lock %d!", c, ldes1); sleep(2); kprintf("\n%c is releasing lock %d!", c, ldes1); releaseall(1, ldes1); }
int waiter2(int lck) { int i; lock(lck, WRITE, 50); kprintf("waiter2 got the lock\n"); releaseall(1, lck); }
int del_test1(char c, int lck){ while(1){ kprintf("Proc %c Locking %d\n",c, lock(lck, WRITE, 10)); sleep(10); releaseall(1,lck); } }
void writer2 (char *msg, int lck) { lock (lck, WRITE, DEFAULT_LOCK_PRIO); testval = testval*10; sleep (3); testval = testval-5; releaseall (1, lck); }
void reader1 (char *msg, int lck) { lock (lck, READ, DEFAULT_LOCK_PRIO); testval = testval*10; sleep (3); testval = testval - 5; releaseall (1, lck); }
int writer(char c, int lck, int prio){ int i; while(1) { lock(lck, WRITE, prio); kprintf("Writer(%c)\n",c); sleep(1); releaseall(1, lck); } }
void procEE() { kprintf ("rdE try to acquire lock 1\n"); int rc = lock(lck1, READ, 5); if(rc == OK) kprintf ("rdE acquires lock 1, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("rdE releases lock 1\n"); releaseall (1, lck1); }
void procFF() { kprintf ("wrF try to acquire lock 2\n"); int rc = lock(lck2, WRITE, 20); if(rc == OK) kprintf ("wrF acquires lock 2, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("wrF releases lock 2\n"); releaseall (1, lck2); }
/*----------------------------------Test 2---------------------------*/ void reader2 (char *msg, int lck) { lock (lck, READ, DEFAULT_LOCK_PRIO); testval = testval*10; //kprintf("\nRtestval : %d",testval); sleep (3); testval = testval-10; //kprintf("\nRtestval : %d",testval); releaseall (1, lck); }
void tooManyLocksAndSomeOtherFuncTests() { int i,j,retval; int ldes[NLOCKS]; kprintf("Launcher %s starting\n",__func__); for(i=0; i<NLOCKS; i++) { ldes[i] = lcreate(); if(ldes[i] < 0) { kprintf("Launcher %s: Unable to get lock. Return: %d. Test failed!\n",__func__,ldes[i]); return; } } j = lcreate(); if(j != SYSERR) { kprintf("Launcher %s: Too many locks getting created. This one should have failed. Return: %d. Test failed!\n",__func__,j); return; } if(SYSERR != (retval = releaseall(1,ldes[30]) ) ) { kprintf("Launcher %s: The release on lock %d should have failed, since we never locked it. Return: %d. Test failed!\n",__func__,ldes[30],retval); return; } if(OK != (retval = ldelete(ldes[30]) ) ) { kprintf("Launcher %s: Delete on the lock %d failed with code %d\n",__func__,ldes[30],retval); return; } if(SYSERR != (retval = releaseall(1,ldes[30]) ) ) { kprintf("Launcher %s: The release on lock %d should have failed, since we've already deleted the lock. Return: %d. Test failed!\n",__func__,ldes[30],retval); return; } j = lcreate(); if(j < 0) { kprintf("Launcher %s: A space for one lock was created. We should have got a lock now. Return: %d. Test failed!\n",__func__,j); return; } ldes[30]=j; for(i=0; i<NLOCKS; i++) { int retval; if(OK != (retval = ldelete(ldes[i]) ) ) { kprintf("Launcher %s: Delete on the lock %d failed with code %d\n",__func__,ldes[i],retval); } } kprintf("Launcher %s completed. Check messages till now for any failures.\n",__func__); }
void procB() { kprintf ("wrB try to acquire lock<%d> 2\n",currpid); int rc = lock(lck2, WRITE, 20); if(rc == OK) kprintf ("wrB acquires lock 2, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("wrB releases lock 2\n"); releaseall (1, lck2); }
void writer2 (char *msg, int lck) { lock (lck, WRITE, DEFAULT_LOCK_PRIO); testval = testval*10; //kprintf("\nWtestval : %d",testval); sleep (3); testval = testval-5; //kprintf("\nWtestval : %d",testval); releaseall (1, lck); }
void procA() { kprintf ("rdA try to acquire lock<%d> 1\n",currpid); int rc = lock(lck1, READ, 20); if(rc == OK) kprintf ("rdA acquires lock 1, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("rdA releases lock 1\n"); releaseall (1, lck1); }
void procAA() { kprintf ("rdA try to acquire lock<%d> 1\n",currpid); int rc = lock(lck1, READ, 20); if(rc == OK) kprintf ("rdA acquires lock 1, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("rdA releases lock 1&3\n"); if(releaseall (2, lck1, lck3) == SYSERR) kprintf("procA doesn't hold this lock\n"); }
int reader(char c, int lck, int prio){ int i; while(1) { lock(lck, READ, prio); kprintf("Reader(%c)\n",c); sleep(1); prio -= 2; releaseall(1, lck); } }
int looper(int lck) { int i; lock(lck, WRITE, 100); for (i=0; i<5; i++) { sleep(1); kprintf("looper pprio: %d\n", proctab[currpid].pprio); kprintf("looper pinh: %d\n", proctab[currpid].pinh); } releaseall(1, lck); }
void writer6 (char i, int lck, int lprio) { //kprintf (" %c: to acquire lock\n", i); lock (lck, WRITE, lprio); output7[count7++]=i; //kprintf (" %c: acquired lock, sleep 3s\n", i); sleep (3); //kprintf (" %c: to release lock\n", i); output7[count7++]=i; releaseall (1, lck); }
void reader3 (char *msg, int lck) { int ret; kprintf (" %s: to acquire lock %d \n", msg,currpid); lock (lck, READ, DEFAULT_LOCK_PRIO); kprintf (" %s: acquired lock\n", msg); sleep(5); kprintf (" %s: to release lock\n", msg); releaseall (1, lck); }
void writer3 (char *msg, int lck) { kprintf (" %s: to acquire lock %d %d\n", msg,currpid, lck); lock (lck, WRITE, DEFAULT_LOCK_PRIO); kprintf (" %s: acquired lock, sleep 10s\n", msg); lock(lck2, WRITE, 30); kprintf("\n\nAcquired both locks, lck2 %d\n\n", lck2); sleep (5); kprintf (" %s: to release lock\n", msg); releaseall (1, lck); }
void procDD() { kprintf ("wrD try to acquire lock 1\n"); int rc = lock(lck1, WRITE, 10); if(rc == OK) kprintf ("wrD acquires lock 1\n"); else kprintf("unable to get lock.\n"); kprintf ("wrD try to acquire lock 2\n"); rc = lock(lck2, WRITE, 10); if(rc == OK) kprintf ("wrD acquires lock 2, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("wrD releases lock 1&2\n"); releaseall (2, lck1, lck2); }
void procCC() { kprintf ("rdC try to acquire lock 1\n"); int rc = lock(lck1, READ, 10); if(rc == OK) kprintf ("rdC acquires lock 1\n"); else kprintf("unable to get lock.\n"); kprintf ("rdC try to acquire lock 2\n"); rc = lock(lck2, READ, 5); if(rc == OK) kprintf ("rdC acquires lock 2, sleep 2s\n"); else kprintf("unable to get lock.\n"); sleep (2); kprintf ("rdC releases lock 1&2\n"); releaseall (2, lck1, lck2); }
void reader6 (char i, int lck, int lprio) { int ret; //kprintf (" %c: to acquire lock\n", i); lock (lck, READ, lprio); output7[count7++]=i; //kprintf (" %c: acquired lock, sleep 3s\n", i); sleep (3); //kprintf (" %c: to release lock\n", i); output7[count7++]=i; releaseall (1, lck); }
void writer(char *msg, int lck, int lprio) { int rc; rc = lock(lck, WRITE, lprio); if (rc == SYSERR) { kprintf (" %s: lock returned SYSERR\n", msg); return; } if (rc == DELETED) { kprintf (" %s: lock was DELETED\n", msg); return; } kprintf (" %s: acquired lock, sleep 3s\n", msg); sleep (3); releaseall (1, lck); }
void proc(char c,int lock1, int waitprio, int locktype) { int i; int count = 0; lock(lock1, locktype, waitprio); while (count++ < LOOP) { kprintf("%c", c); for (i = 0; i < 10000000; i++);//this is to introduce latency between prints } sleep(1); /* So that other processes go ahead and try to acquire the lock */ releaseall(1,lock1); }
int peak_load_test(char c){ int lck[50]; int i; for(i=0; i<50; i++){ lck[i] = lcreate(); if(OK != lock(lck[i], WRITE, 10)){ kprintf("Test Failed!! \n"); return; } } for(i=0; i<50; i++){ if(OK == lock(lck[i], WRITE, 10)){ kprintf("Test Failed!! \n"); return; } } for(i=0; i<50; i += 5){ if(OK != releaseall(5, lck[i], lck[i+1], lck[i+2], lck[i+3], lck[i+4])){ kprintf("Test Failed!! \n"); return; } } for(i=0; i<50; i++){ if(OK != ldelete(lck[i])){ kprintf("Test Failed!! \n"); return; } } lck[0] = lcreate(); if(OK != lock(lck[0], READ, 10)){ kprintf("Test Failed!! \n"); return; } releaseall(1, lck[0]); ldelete(lck[0]); }
void proc_del_lock(char c,int lock1, int waitprio, int locktype) { int i; int count = 0; lock(lock1, locktype, waitprio); while (count++ < LOOP) { kprintf("%c", c); for (i = 0; i < 10000000; i++);//this is to introduce latency between prints } sleep(1); /* So that other processes go ahead and try to acquire the lock */ ldelete(lock1); /* Delete the lock here so that the reader should return an error */ sleep(1); releaseall(1,lock1); }