Rev 3022 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
Line 72... | Line 72... | ||
72 | waitq_sleep(&can_start); |
72 | waitq_sleep(&can_start); |
73 | 73 | ||
74 | to = random(40000); |
74 | to = random(40000); |
75 | 75 | ||
76 | if (!sh_quiet) |
76 | if (!sh_quiet) |
77 | printf("cpu%d, tid %llu w+ (%d)\n", CPU->id, THREAD->tid, to); |
77 | printf("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); |
78 | 78 | ||
79 | rc = rwlock_write_lock_timeout(&rwlock, to); |
79 | rc = rwlock_write_lock_timeout(&rwlock, to); |
80 | if (SYNCH_FAILED(rc)) { |
80 | if (SYNCH_FAILED(rc)) { |
81 | if (!sh_quiet) |
81 | if (!sh_quiet) |
82 | printf("cpu%d, tid %llu w!\n", CPU->id, THREAD->tid); |
82 | printf("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); |
83 | atomic_dec(&thread_count); |
83 | atomic_dec(&thread_count); |
84 | return; |
84 | return; |
85 | } |
85 | } |
86 | 86 | ||
87 | if (!sh_quiet) |
87 | if (!sh_quiet) |
88 | printf("cpu%d, tid %llu w=\n", CPU->id, THREAD->tid); |
88 | printf("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); |
89 | 89 | ||
90 | if (rwlock.readers_in) { |
90 | if (rwlock.readers_in) { |
91 | if (!sh_quiet) |
91 | if (!sh_quiet) |
92 | printf("Oops."); |
92 | printf("Oops."); |
93 | atomic_inc(&threads_fault); |
93 | atomic_inc(&threads_fault); |
Line 104... | Line 104... | ||
104 | } |
104 | } |
105 | 105 | ||
106 | rwlock_write_unlock(&rwlock); |
106 | rwlock_write_unlock(&rwlock); |
107 | 107 | ||
108 | if (!sh_quiet) |
108 | if (!sh_quiet) |
109 | printf("cpu%d, tid %llu w-\n", CPU->id, THREAD->tid); |
109 | printf("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); |
110 | atomic_dec(&thread_count); |
110 | atomic_dec(&thread_count); |
111 | } |
111 | } |
112 | 112 | ||
113 | static void reader(void *arg) |
113 | static void reader(void *arg) |
114 | { |
114 | { |
Line 117... | Line 117... | ||
117 | waitq_sleep(&can_start); |
117 | waitq_sleep(&can_start); |
118 | 118 | ||
119 | to = random(2000); |
119 | to = random(2000); |
120 | 120 | ||
121 | if (!sh_quiet) |
121 | if (!sh_quiet) |
122 | printf("cpu%d, tid %llu r+ (%d)\n", CPU->id, THREAD->tid, to); |
122 | printf("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); |
123 | 123 | ||
124 | rc = rwlock_read_lock_timeout(&rwlock, to); |
124 | rc = rwlock_read_lock_timeout(&rwlock, to); |
125 | if (SYNCH_FAILED(rc)) { |
125 | if (SYNCH_FAILED(rc)) { |
126 | if (!sh_quiet) |
126 | if (!sh_quiet) |
127 | printf("cpu%d, tid %llu r!\n", CPU->id, THREAD->tid); |
127 | printf("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); |
128 | atomic_dec(&thread_count); |
128 | atomic_dec(&thread_count); |
129 | return; |
129 | return; |
130 | } |
130 | } |
131 | 131 | ||
132 | if (!sh_quiet) |
132 | if (!sh_quiet) |
133 | printf("cpu%d, tid %llu r=\n", CPU->id, THREAD->tid); |
133 | printf("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); |
134 | 134 | ||
135 | thread_usleep(30000); |
135 | thread_usleep(30000); |
136 | rwlock_read_unlock(&rwlock); |
136 | rwlock_read_unlock(&rwlock); |
137 | 137 | ||
138 | if (!sh_quiet) |
138 | if (!sh_quiet) |
139 | printf("cpu%d, tid %llu r-\n", CPU->id, THREAD->tid); |
139 | printf("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); |
140 | atomic_dec(&thread_count); |
140 | atomic_dec(&thread_count); |
141 | } |
141 | } |
142 | 142 | ||
143 | char * test_rwlock4(bool quiet) |
143 | char * test_rwlock4(bool quiet) |
144 | { |
144 | { |
Line 157... | Line 157... | ||
157 | 157 | ||
158 | thread_t *thrd; |
158 | thread_t *thrd; |
159 | 159 | ||
160 | context_save(&ctx); |
160 | context_save(&ctx); |
161 | if (!quiet) { |
161 | if (!quiet) { |
162 | printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); |
162 | printf("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in); |
163 | printf("Creating %d readers\n", rd); |
163 | printf("Creating %" PRIu32 " readers\n", rd); |
164 | } |
164 | } |
165 | 165 | ||
166 | for (i = 0; i < rd; i++) { |
166 | for (i = 0; i < rd; i++) { |
167 | thrd = thread_create(reader, NULL, TASK, 0, "reader", false); |
167 | thrd = thread_create(reader, NULL, TASK, 0, "reader", false); |
168 | if (thrd) |
168 | if (thrd) |
169 | thread_ready(thrd); |
169 | thread_ready(thrd); |
170 | else if (!quiet) |
170 | else if (!quiet) |
171 | printf("Could not create reader %d\n", i); |
171 | printf("Could not create reader %" PRIu32 "\n", i); |
172 | } |
172 | } |
173 | 173 | ||
174 | if (!quiet) |
174 | if (!quiet) |
175 | printf("Creating %d writers\n", wr); |
175 | printf("Creating %" PRIu32 " writers\n", wr); |
176 | 176 | ||
177 | for (i = 0; i < wr; i++) { |
177 | for (i = 0; i < wr; i++) { |
178 | thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
178 | thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
179 | if (thrd) |
179 | if (thrd) |
180 | thread_ready(thrd); |
180 | thread_ready(thrd); |
181 | else if (!quiet) |
181 | else if (!quiet) |
182 | printf("Could not create writer %d\n", i); |
182 | printf("Could not create writer %" PRIu32 "\n", i); |
183 | } |
183 | } |
184 | 184 | ||
185 | thread_usleep(20000); |
185 | thread_usleep(20000); |
186 | waitq_wakeup(&can_start, WAKEUP_ALL); |
186 | waitq_wakeup(&can_start, WAKEUP_ALL); |
187 | 187 | ||
188 | while (atomic_get(&thread_count) > 0) { |
188 | while (atomic_get(&thread_count) > 0) { |
189 | if (!quiet) |
189 | if (!quiet) |
190 | printf("Threads left: %d\n", atomic_get(&thread_count)); |
190 | printf("Threads left: %ld\n", atomic_get(&thread_count)); |
191 | thread_sleep(1); |
191 | thread_sleep(1); |
192 | } |
192 | } |
193 | 193 | ||
194 | if (atomic_get(&threads_fault) == 0) |
194 | if (atomic_get(&threads_fault) == 0) |
195 | return NULL; |
195 | return NULL; |