Changeset cb01e1e in mainline for kernel/test/synch/rwlock4.c
- Timestamp:
- 2009-04-04T00:26:27Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a85aebd
- Parents:
- 171f9a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/synch/rwlock4.c
r171f9a1 rcb01e1e 41 41 #include <synch/spinlock.h> 42 42 43 #define READERS 44 #define WRITERS 43 #define READERS 50 44 #define WRITERS 50 45 45 46 46 static atomic_t thread_count; 47 47 static rwlock_t rwlock; 48 48 static atomic_t threads_fault; 49 static bool sh_quiet;50 49 51 50 SPINLOCK_INITIALIZE(rw_lock); … … 58 57 { 59 58 uint32_t rc; 60 61 spinlock_lock(&rw_lock); 59 60 spinlock_lock(&rw_lock); 62 61 rc = seed % max; 63 62 seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc; … … 71 70 thread_detach(THREAD); 72 71 waitq_sleep(&can_start); 73 72 74 73 to = random(40000); 75 74 76 if (!sh_quiet) 77 printf("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); 75 TPRINTF("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); 78 76 79 77 rc = rwlock_write_lock_timeout(&rwlock, to); 80 78 if (SYNCH_FAILED(rc)) { 81 if (!sh_quiet) 82 printf("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); 79 TPRINTF("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); 83 80 atomic_dec(&thread_count); 84 81 return; 85 82 } 86 83 87 if (!sh_quiet) 88 printf("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); 89 84 TPRINTF("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); 85 90 86 if (rwlock.readers_in) { 91 if (!sh_quiet) 92 printf("Oops."); 87 TPRINTF("Oops.\n"); 93 88 atomic_inc(&threads_fault); 94 89 atomic_dec(&thread_count); 95 90 return; 96 91 } 92 97 93 thread_usleep(random(1000000)); 94 98 95 if (rwlock.readers_in) { 99 if (!sh_quiet) 100 printf("Oops."); 96 TPRINTF("Oops.\n"); 101 97 atomic_inc(&threads_fault); 102 98 atomic_dec(&thread_count); 103 99 return; 104 100 } 105 101 106 102 rwlock_write_unlock(&rwlock); 107 103 108 if (!sh_quiet) 109 printf("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); 104 TPRINTF("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); 110 105 atomic_dec(&thread_count); 111 106 } … … 119 114 to = random(2000); 120 115 121 if (!sh_quiet) 122 printf("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); 116 TPRINTF("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); 123 117 124 118 rc = rwlock_read_lock_timeout(&rwlock, to); 125 119 if (SYNCH_FAILED(rc)) { 126 if (!sh_quiet) 127 printf("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); 120 TPRINTF("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); 128 121 atomic_dec(&thread_count); 129 122 return; 130 123 } 131 124 132 if (!sh_quiet) 133 printf("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); 125 TPRINTF("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); 134 126 135 127 thread_usleep(30000); 136 128 rwlock_read_unlock(&rwlock); 137 129 138 if (!sh_quiet) 139 printf("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); 130 TPRINTF("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); 140 131 atomic_dec(&thread_count); 141 132 } 142 133 143 char * test_rwlock4(bool quiet)134 char *test_rwlock4(void) 144 135 { 145 136 context_t ctx; 146 137 uint32_t i; 147 sh_quiet = quiet;148 138 149 139 waitq_initialize(&can_start); … … 159 149 160 150 context_save(&ctx); 161 if (!quiet) { 162 printf("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in); 163 printf("Creating %" PRIu32 " readers\n", rd); 164 } 151 TPRINTF("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in); 152 TPRINTF("Creating %" PRIu32 " readers\n", rd); 165 153 166 154 for (i = 0; i < rd; i++) { … … 168 156 if (thrd) 169 157 thread_ready(thrd); 170 else if (!quiet)171 printf("Could not create reader %" PRIu32 "\n", i);158 else 159 TPRINTF("Could not create reader %" PRIu32 "\n", i); 172 160 } 173 174 if (!quiet) 175 printf("Creating %" PRIu32 " writers\n", wr); 161 162 TPRINTF("Creating %" PRIu32 " writers\n", wr); 176 163 177 164 for (i = 0; i < wr; i++) { … … 179 166 if (thrd) 180 167 thread_ready(thrd); 181 else if (!quiet)182 printf("Could not create writer %" PRIu32 "\n", i);168 else 169 TPRINTF("Could not create writer %" PRIu32 "\n", i); 183 170 } 184 171 … … 187 174 188 175 while (atomic_get(&thread_count) > 0) { 189 if (!quiet) 190 printf("Threads left: %ld\n", atomic_get(&thread_count)); 176 TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); 191 177 thread_sleep(1); 192 178 }
Note:
See TracChangeset
for help on using the changeset viewer.