Changeset 96348adc in mainline for kernel/test/synch/rwlock5.c
- Timestamp:
- 2006-12-12T17:24:58Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e13972
- Parents:
- 34db7fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/synch/rwlock5.c
r34db7fa r96348adc 45 45 static atomic_t items_written; 46 46 47 static void writer(void *arg); 48 static void reader(void *arg); 49 static void failed(void); 50 51 void writer(void *arg) 47 static void writer(void *arg) 52 48 { 53 49 thread_detach(THREAD); … … 60 56 } 61 57 62 void reader(void *arg)58 static void reader(void *arg) 63 59 { 64 60 thread_detach(THREAD); … … 71 67 } 72 68 73 void failed(void) 74 { 75 printf("Test failed prematurely.\n"); 76 thread_exit(); 77 } 78 79 void test_rwlock5(void) 69 char * test_rwlock5(void) 80 70 { 81 71 int i, j, k; 82 72 count_t readers, writers; 83 73 84 printf("Read/write locks test #5\n");85 86 74 waitq_initialize(&can_start); 87 75 rwlock_initialize(&rwlock); 88 76 89 for (i =1; i<=3; i++) {77 for (i = 1; i <= 3; i++) { 90 78 thread_t *thrd; 91 79 … … 93 81 atomic_set(&items_written, 0); 94 82 95 readers = i *READERS;96 writers = (4 -i)*WRITERS;83 readers = i * READERS; 84 writers = (4 - i) * WRITERS; 97 85 98 86 printf("Creating %ld readers and %ld writers...", readers, writers); 99 87 100 for (j =0; j<(READERS+WRITERS)/2; j++) {101 for (k =0; k<i; k++) {88 for (j = 0; j < (READERS + WRITERS) / 2; j++) { 89 for (k = 0; k < i; k++) { 102 90 thrd = thread_create(reader, NULL, TASK, 0, "reader"); 103 91 if (thrd) 104 92 thread_ready(thrd); 105 93 else 106 failed();94 printf("Could not create reader %d\n", k); 107 95 } 108 for (k =0; k<(4-i); k++) {96 for (k = 0; k < (4 - i); k++) { 109 97 thrd = thread_create(writer, NULL, TASK, 0, "writer"); 110 98 if (thrd) 111 99 thread_ready(thrd); 112 100 else 113 failed();101 printf("Could not create writer %d\n", k); 114 102 } 115 103 } … … 120 108 waitq_wakeup(&can_start, WAKEUP_ALL); 121 109 122 while ( items_read.count != readers || items_written.count != writers) {110 while ((items_read.count != readers) || (items_written.count != writers)) { 123 111 printf("%zd readers remaining, %zd writers remaining, readers_in=%zd\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in); 124 112 thread_usleep(100000); 125 113 } 126 114 } 127 printf("Test passed.\n"); 115 116 return NULL; 128 117 }
Note:
See TracChangeset
for help on using the changeset viewer.