Changeset ee42e43 in mainline
- Timestamp:
- 2010-06-22T11:29:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a49a1a1
- Parents:
- fdaad75d
- Location:
- kernel
- Files:
-
- 12 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile
rfdaad75d ree42e43 241 241 generic/src/synch/spinlock.c \ 242 242 generic/src/synch/condvar.c \ 243 generic/src/synch/rwlock.c \244 243 generic/src/synch/mutex.c \ 245 244 generic/src/synch/semaphore.c \ … … 294 293 test/mm/slab1.c \ 295 294 test/mm/slab2.c \ 296 test/synch/rwlock1.c \297 test/synch/rwlock2.c \298 test/synch/rwlock3.c \299 test/synch/rwlock4.c \300 test/synch/rwlock5.c \301 295 test/synch/semaphore1.c \ 302 296 test/synch/semaphore2.c \ -
kernel/generic/include/proc/task.h
rfdaad75d ree42e43 40 40 #include <synch/spinlock.h> 41 41 #include <synch/mutex.h> 42 #include <synch/rwlock.h>43 42 #include <synch/futex.h> 44 43 #include <adt/avl.h> -
kernel/generic/include/proc/thread.h
rfdaad75d ree42e43 40 40 #include <time/timeout.h> 41 41 #include <cpu.h> 42 #include <synch/rwlock.h>43 42 #include <synch/spinlock.h> 44 43 #include <adt/avl.h> … … 155 154 int fpu_context_engaged; 156 155 157 rwlock_type_t rwlock_holder_type;158 159 /** Callback fired in scheduler before the thread is put asleep. */160 void (* call_me)(void *);161 /** Argument passed to call_me(). */162 void *call_me_with;163 164 156 /** Thread's state. */ 165 157 state_t state; … … 239 231 extern void thread_detach(thread_t *); 240 232 241 extern void thread_register_call_me(void (*)(void *), void *);242 233 extern void thread_print_list(bool); 243 234 extern void thread_destroy(thread_t *, bool); -
kernel/generic/src/proc/scheduler.c
rfdaad75d ree42e43 455 455 irq_spinlock_unlock(&THREAD->sleep_queue->lock, false); 456 456 457 /*458 * Check for possible requests for out-of-context459 * invocation.460 *461 */462 if (THREAD->call_me) {463 THREAD->call_me(THREAD->call_me_with);464 THREAD->call_me = NULL;465 THREAD->call_me_with = NULL;466 }467 468 457 irq_spinlock_unlock(&THREAD->lock, false); 469 470 458 break; 471 459 -
kernel/generic/src/proc/thread.c
rfdaad75d ree42e43 48 48 #include <synch/spinlock.h> 49 49 #include <synch/waitq.h> 50 #include <synch/rwlock.h>51 50 #include <cpu.h> 52 51 #include <str.h> … … 329 328 thread->flags = flags; 330 329 thread->state = Entering; 331 thread->call_me = NULL;332 thread->call_me_with = NULL;333 330 334 331 timeout_initialize(&thread->sleep_timeout); … … 343 340 thread->detached = false; 344 341 waitq_initialize(&thread->join_wq); 345 346 thread->rwlock_holder_type = RWLOCK_NONE;347 342 348 343 thread->task = task; … … 583 578 584 579 (void) waitq_sleep_timeout(&wq, usec, SYNCH_FLAGS_NON_BLOCKING); 585 }586 587 /** Register thread out-of-context invocation588 *589 * Register a function and its argument to be executed590 * on next context switch to the current thread. Must591 * be called with interrupts disabled.592 *593 * @param call_me Out-of-context function.594 * @param call_me_with Out-of-context function argument.595 *596 */597 void thread_register_call_me(void (* call_me)(void *), void *call_me_with)598 {599 irq_spinlock_lock(&THREAD->lock, false);600 THREAD->call_me = call_me;601 THREAD->call_me_with = call_me_with;602 irq_spinlock_unlock(&THREAD->lock, false);603 580 } 604 581 -
kernel/generic/src/synch/futex.c
rfdaad75d ree42e43 37 37 38 38 #include <synch/futex.h> 39 #include <synch/ rwlock.h>39 #include <synch/mutex.h> 40 40 #include <synch/spinlock.h> 41 41 #include <synch/synch.h> … … 65 65 66 66 /** 67 * Read-write lockprotecting global futex hash table.67 * Mutex protecting global futex hash table. 68 68 * It is also used to serialize access to all futex_t structures. 69 69 * Must be acquired before the task futex B+tree lock. 70 70 */ 71 static rwlock_t futex_ht_lock;71 static mutex_t futex_ht_lock; 72 72 73 73 /** Futex hash table. */ … … 84 84 void futex_init(void) 85 85 { 86 rwlock_initialize(&futex_ht_lock);86 mutex_initialize(&futex_ht_lock, MUTEX_PASSIVE); 87 87 hash_table_create(&futex_ht, FUTEX_HT_SIZE, 1, &futex_ht_ops); 88 88 } … … 194 194 * or allocate new one if it does not exist already. 195 195 */ 196 rwlock_read_lock(&futex_ht_lock);196 mutex_lock(&futex_ht_lock); 197 197 item = hash_table_find(&futex_ht, &paddr); 198 198 if (item) { … … 206 206 /* 207 207 * The futex is new to the current task. 208 * However, we only have read access.209 * Gain write access and try again.208 * Upgrade its reference count and put it to the 209 * current task's B+tree of known futexes. 210 210 */ 211 mutex_unlock(&TASK->futexes_lock);212 goto gain_write_access;211 futex->refcount++; 212 btree_insert(&TASK->futexes, paddr, futex, leaf); 213 213 } 214 214 mutex_unlock(&TASK->futexes_lock); 215 216 rwlock_read_unlock(&futex_ht_lock);217 215 } else { 218 gain_write_access: 216 futex = (futex_t *) malloc(sizeof(futex_t), 0); 217 futex_initialize(futex); 218 futex->paddr = paddr; 219 hash_table_insert(&futex_ht, &paddr, &futex->ht_link); 220 219 221 /* 220 * Upgrade to writer is not currently supported,221 * therefore, it is necessary to release the read lock222 * and reacquire it as a writer.222 * This is the first task referencing the futex. 223 * It can be directly inserted into its 224 * B+tree of known futexes. 223 225 */ 224 rwlock_read_unlock(&futex_ht_lock); 225 226 rwlock_write_lock(&futex_ht_lock); 227 /* 228 * Avoid possible race condition by searching 229 * the hash table once again with write access. 230 */ 231 item = hash_table_find(&futex_ht, &paddr); 232 if (item) { 233 futex = hash_table_get_instance(item, futex_t, ht_link); 234 235 /* 236 * See if this futex is known to the current task. 237 */ 238 mutex_lock(&TASK->futexes_lock); 239 if (!btree_search(&TASK->futexes, paddr, &leaf)) { 240 /* 241 * The futex is new to the current task. 242 * Upgrade its reference count and put it to the 243 * current task's B+tree of known futexes. 244 */ 245 futex->refcount++; 246 btree_insert(&TASK->futexes, paddr, futex, 247 leaf); 248 } 249 mutex_unlock(&TASK->futexes_lock); 250 251 rwlock_write_unlock(&futex_ht_lock); 252 } else { 253 futex = (futex_t *) malloc(sizeof(futex_t), 0); 254 futex_initialize(futex); 255 futex->paddr = paddr; 256 hash_table_insert(&futex_ht, &paddr, &futex->ht_link); 257 258 /* 259 * This is the first task referencing the futex. 260 * It can be directly inserted into its 261 * B+tree of known futexes. 262 */ 263 mutex_lock(&TASK->futexes_lock); 264 btree_insert(&TASK->futexes, paddr, futex, NULL); 265 mutex_unlock(&TASK->futexes_lock); 266 267 rwlock_write_unlock(&futex_ht_lock); 268 } 226 mutex_lock(&TASK->futexes_lock); 227 btree_insert(&TASK->futexes, paddr, futex, NULL); 228 mutex_unlock(&TASK->futexes_lock); 229 269 230 } 231 mutex_unlock(&futex_ht_lock); 270 232 271 233 return futex; … … 318 280 link_t *cur; 319 281 320 rwlock_write_lock(&futex_ht_lock);282 mutex_lock(&futex_ht_lock); 321 283 mutex_lock(&TASK->futexes_lock); 322 284 … … 338 300 339 301 mutex_unlock(&TASK->futexes_lock); 340 rwlock_write_unlock(&futex_ht_lock);302 mutex_unlock(&futex_ht_lock); 341 303 } 342 304 -
kernel/test/test.c
rfdaad75d ree42e43 51 51 #include <mm/slab1.def> 52 52 #include <mm/slab2.def> 53 #include <synch/rwlock1.def>54 #include <synch/rwlock2.def>55 #include <synch/rwlock3.def>56 #include <synch/rwlock4.def>57 #include <synch/rwlock5.def>58 53 #include <synch/semaphore1.def> 59 54 #include <synch/semaphore2.def> -
kernel/test/test.h
rfdaad75d ree42e43 70 70 extern const char *test_slab1(void); 71 71 extern const char *test_slab2(void); 72 extern const char *test_rwlock1(void);73 extern const char *test_rwlock2(void);74 extern const char *test_rwlock3(void);75 extern const char *test_rwlock4(void);76 extern const char *test_rwlock5(void);77 72 extern const char *test_semaphore1(void); 78 73 extern const char *test_semaphore2(void);
Note:
See TracChangeset
for help on using the changeset viewer.