55 |
void |
void |
56 |
thread_lock_write (struct thread_lock *lock) |
thread_lock_write (struct thread_lock *lock) |
57 |
{ |
{ |
58 |
|
SPL_T spl = SPLOFF (); |
59 |
|
|
60 |
spin_lock (&lock->interlock); |
spin_lock (&lock->interlock); |
61 |
|
|
62 |
if (lock->thread == THREAD_CURRENT ()) |
if (lock->thread == THREAD_CURRENT ()) |
63 |
{ |
{ |
64 |
lock->recursion_depth++; |
lock->recursion_depth++; |
65 |
spin_unlock (&lock->interlock); |
spin_unlock (&lock->interlock); |
66 |
|
SPLON (spl); |
67 |
return; |
return; |
68 |
} |
} |
69 |
|
|
85 |
THREAD_CURRENT()->blocked_lock = lock; |
THREAD_CURRENT()->blocked_lock = lock; |
86 |
|
|
87 |
ASSERT (lock->owner != (struct thread *) -1); |
ASSERT (lock->owner != (struct thread *) -1); |
88 |
|
#if 0 |
89 |
if (lock->can_lend && thread_system_running) |
if (lock->can_lend && thread_system_running) |
90 |
thread_will_priority (lock->owner); |
thread_will_priority (lock->owner); |
91 |
|
#endif |
92 |
thread_sleep ((int) lock, & lock->interlock, 0); |
thread_sleep ((int) lock, & lock->interlock, 0); |
93 |
THREAD_CURRENT()->blocked_lock = 0; |
THREAD_CURRENT()->blocked_lock = 0; |
94 |
spin_lock (&lock->interlock); |
spin_lock (&lock->interlock); |
114 |
lock->waiting = true; |
lock->waiting = true; |
115 |
THREAD_CURRENT()->blocked_lock = lock; |
THREAD_CURRENT()->blocked_lock = lock; |
116 |
|
|
117 |
ASSERT (lock->owner != (struct thread *) -1); |
#if 0 |
118 |
if (lock->can_lend && thread_system_running) |
if (lock->can_lend && thread_system_running) |
119 |
thread_will_priority (lock->owner); |
thread_will_priority (lock->owner); |
120 |
|
#endif |
121 |
thread_sleep ((int) lock, &lock->interlock, 0); |
thread_sleep ((int) lock, &lock->interlock, 0); |
122 |
THREAD_CURRENT()->blocked_lock = 0; |
THREAD_CURRENT()->blocked_lock = 0; |
123 |
spin_lock (&lock->interlock); |
spin_lock (&lock->interlock); |
126 |
|
|
127 |
lock->owner = THREAD_CURRENT (); |
lock->owner = THREAD_CURRENT (); |
128 |
spin_unlock (&lock->interlock); |
spin_unlock (&lock->interlock); |
129 |
|
SPLON (spl); |
130 |
} |
} |
131 |
|
|
132 |
/* Lock LOCK for reading. Wait for the writer (if any) to finish before |
/* Lock LOCK for reading. Wait for the writer (if any) to finish before |
179 |
thread_lock_unlock (struct thread_lock *lock) |
thread_lock_unlock (struct thread_lock *lock) |
180 |
{ |
{ |
181 |
bool wakeup = false; |
bool wakeup = false; |
182 |
|
SPL_T spl = SPLOFF (); |
183 |
|
|
184 |
spin_lock (&lock->interlock); |
spin_lock (&lock->interlock); |
185 |
|
|
202 |
} |
} |
203 |
|
|
204 |
spin_unlock (&lock->interlock); |
spin_unlock (&lock->interlock); |
205 |
|
SPLON (spl); |
206 |
|
#if 0 |
207 |
if (lock->can_lend && thread_system_running |
if (lock->can_lend && thread_system_running |
208 |
&& THREAD_CURRENT()->inherited_priority_p) |
&& THREAD_CURRENT()->inherited_priority_p) |
209 |
thread_waive_priority (THREAD_CURRENT ()); |
thread_waive_priority (THREAD_CURRENT ()); |
210 |
|
#endif |
211 |
if (wakeup) |
if (wakeup) |
212 |
{ |
{ |
213 |
thread_wakeup ((int) lock); |
thread_wakeup ((int) lock); |
220 |
bool |
bool |
221 |
thread_lock_read_to_write (struct thread_lock *lock) |
thread_lock_read_to_write (struct thread_lock *lock) |
222 |
{ |
{ |
223 |
|
SPL_T spl = SPLOFF (); |
224 |
|
|
225 |
spin_lock(&lock->interlock); |
spin_lock(&lock->interlock); |
226 |
lock->read_count--; |
lock->read_count--; |
227 |
|
|
246 |
else |
else |
247 |
spin_unlock (&lock->interlock); |
spin_unlock (&lock->interlock); |
248 |
|
|
249 |
|
SPLON (spl); |
250 |
return true; |
return true; |
251 |
} |
} |
252 |
|
|
277 |
} |
} |
278 |
|
|
279 |
spin_unlock (&lock->interlock); |
spin_unlock (&lock->interlock); |
280 |
|
SPLON (spl); |
281 |
return false; |
return false; |
282 |
} |
} |
283 |
|
|