Changeset deada67 in mainline for kernel/test/synch/rwlock4.c
- Timestamp:
- 2006-12-19T17:54:50Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 730376d
- Parents:
- 6536a4a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/synch/rwlock4.c
r6536a4a9 rdeada67 44 44 #define WRITERS 50 45 45 46 static atomic_t thread_count; 46 47 static rwlock_t rwlock; 47 48 static atomic_t threads_fault; 49 static bool sh_quiet; 48 50 49 51 SPINLOCK_INITIALIZE(rw_lock); … … 71 73 72 74 to = random(40000); 73 printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to); 75 76 if (!sh_quiet) 77 printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to); 78 74 79 rc = rwlock_write_lock_timeout(&rwlock, to); 75 80 if (SYNCH_FAILED(rc)) { 76 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 81 if (!sh_quiet) 82 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 83 atomic_dec(&thread_count); 77 84 return; 78 85 } 79 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 86 87 if (!sh_quiet) 88 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 80 89 81 90 if (rwlock.readers_in) { 82 printf("Oops."); 91 if (!sh_quiet) 92 printf("Oops."); 83 93 atomic_inc(&threads_fault); 94 atomic_dec(&thread_count); 84 95 return; 85 96 } 86 97 thread_usleep(random(1000000)); 87 98 if (rwlock.readers_in) { 88 printf("Oops."); 99 if (!sh_quiet) 100 printf("Oops."); 89 101 atomic_inc(&threads_fault); 102 atomic_dec(&thread_count); 90 103 return; 91 104 } 92 105 93 106 rwlock_write_unlock(&rwlock); 94 printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); 107 108 if (!sh_quiet) 109 printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); 110 atomic_dec(&thread_count); 95 111 } 96 112 … … 102 118 103 119 to = random(2000); 104 printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to); 120 121 if (!sh_quiet) 122 printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to); 123 105 124 rc = rwlock_read_lock_timeout(&rwlock, to); 106 125 if (SYNCH_FAILED(rc)) { 107 printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid); 126 if (!sh_quiet) 127 printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid); 128 atomic_dec(&thread_count); 108 129 return; 109 130 } 110 printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid); 131 132 if (!sh_quiet) 133 printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid); 134 111 135 thread_usleep(30000); 112 136 rwlock_read_unlock(&rwlock); 113 printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); 137 138 if (!sh_quiet) 139 printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); 140 atomic_dec(&thread_count); 114 141 } 115 142 … … 117 144 { 118 145 context_t ctx; 119 uint32_t i, k; 146 uint32_t i; 147 sh_quiet = quiet; 120 148 121 149 waitq_initialize(&can_start); … … 123 151 atomic_set(&threads_fault, 0); 124 152 153 uint32_t rd = random(7) + 1; 154 uint32_t wr = random(5) + 1; 155 156 atomic_set(&thread_count, rd + wr); 157 125 158 thread_t *thrd; 126 159 127 160 context_save(&ctx); 128 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 161 if (!quiet) { 162 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 163 printf("Creating %d readers\n", rd); 164 } 129 165 130 k = random(7) + 1; 131 printf("Creating %d readers\n", k); 132 for (i = 0; i < k; i++) { 166 for (i = 0; i < rd; i++) { 133 167 thrd = thread_create(reader, NULL, TASK, 0, "reader", false); 134 168 if (thrd) 135 169 thread_ready(thrd); 136 else 170 else if (!quiet) 137 171 printf("Could not create reader %d\n", i); 138 172 } 139 173 140 k = random(5) + 1; 141 printf("Creating %d writers\n", k); 142 for (i = 0; i < k; i++) { 174 if (!quiet) 175 printf("Creating %d writers\n", wr); 176 177 for (i = 0; i < wr; i++) { 143 178 thrd = thread_create(writer, NULL, TASK, 0, "writer", false); 144 179 if (thrd) 145 180 thread_ready(thrd); 146 else 181 else if (!quiet) 147 182 printf("Could not create writer %d\n", i); 148 183 } … … 151 186 waitq_wakeup(&can_start, WAKEUP_ALL); 152 187 188 while (atomic_get(&thread_count) > 0) { 189 if (!quiet) 190 printf("Threads left: %d\n", atomic_get(&thread_count)); 191 thread_sleep(1); 192 } 193 153 194 if (atomic_get(&threads_fault) == 0) 154 195 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.