Changeset 207e8880 in mainline for kernel/generic/src/synch/futex.c
- Timestamp:
- 2012-12-05T22:36:42Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b1c57a8
- Parents:
- 6a585dd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/futex.c
r6a585dd r207e8880 121 121 * Acquire task specific TASK->futex_list_lock before this mutex. 122 122 */ 123 static mutex_t futex_ht_lock;123 SPINLOCK_STATIC_INITIALIZE_NAME(futex_ht_lock, "futex-ht-lock"); 124 124 125 125 /** Global kernel futex hash table. Lock futex_ht_lock before accessing. … … 148 148 void futex_init(void) 149 149 { 150 mutex_initialize(&futex_ht_lock, MUTEX_PASSIVE);151 150 hash_table_create(&futex_ht, FUTEX_HT_SIZE, 1, &futex_ht_ops); 152 151 } … … 160 159 161 160 list_initialize(&task->futexes->list); 162 mutex_initialize(&task->futexes->list_lock, MUTEX_PASSIVE);161 spinlock_initialize(&task->futexes->list_lock, "futex-list-lock"); 163 162 } 164 163 … … 206 205 207 206 /* All threads of this task have terminated. This is the last thread. */ 208 mutex_lock(&futexes->list_lock);207 spinlock_lock(&futexes->list_lock); 209 208 210 209 list_foreach_safe(futexes->list, cur_link, next_link) { … … 222 221 } 223 222 224 mutex_unlock(&futexes->list_lock);223 spinlock_unlock(&futexes->list_lock); 225 224 } 226 225 … … 242 241 static void futex_add_ref(futex_t *futex) 243 242 { 244 ASSERT( mutex_locked(&futex_ht_lock));243 ASSERT(spinlock_locked(&futex_ht_lock)); 245 244 ASSERT(0 < futex->refcount); 246 245 ++futex->refcount; … … 250 249 static void futex_release_ref(futex_t *futex) 251 250 { 252 ASSERT( mutex_locked(&futex_ht_lock));251 ASSERT(spinlock_locked(&futex_ht_lock)); 253 252 ASSERT(0 < futex->refcount); 254 253 … … 263 262 static void futex_release_ref_locked(futex_t *futex) 264 263 { 265 mutex_lock(&futex_ht_lock);264 spinlock_lock(&futex_ht_lock); 266 265 futex_release_ref(futex); 267 mutex_unlock(&futex_ht_lock);266 spinlock_unlock(&futex_ht_lock); 268 267 } 269 268 … … 278 277 uintptr_t paddr; 279 278 280 if (!find_futex_paddr(uaddr, &paddr)) 279 if (!find_futex_paddr(uaddr, &paddr)) { 281 280 return 0; 281 } 282 282 283 283 return get_and_cache_futex(paddr, uaddr); … … 288 288 static bool find_futex_paddr(uintptr_t uaddr, uintptr_t *paddr) 289 289 { 290 page_table_lock(AS, true); 290 spinlock_lock(&futex_ht_lock); 291 page_table_lock(AS, false); 291 292 292 293 bool found = false; 293 pte_t *t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE), false);294 pte_t *t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE), true); 294 295 295 296 if (t && PTE_VALID(t) && PTE_PRESENT(t)) { … … 298 299 } 299 300 300 page_table_unlock(AS, true); 301 page_table_unlock(AS, false); 302 spinlock_unlock(&futex_ht_lock); 301 303 302 304 return found; … … 338 340 * if it is not present). 339 341 */ 340 mutex_lock(&futex_ht_lock);342 spinlock_lock(&futex_ht_lock); 341 343 342 344 link_t *fut_link = hash_table_find(&futex_ht, &phys_addr); … … 351 353 } 352 354 353 mutex_unlock(&futex_ht_lock);355 spinlock_unlock(&futex_ht_lock); 354 356 355 357 /* … … 366 368 /* Cache the mapping from the virtual address to the futex for this task. */ 367 369 if (cht_insert_unique(&TASK->futexes->ht, &fut_ptr->cht_link, &dup_link)) { 368 mutex_lock(&TASK->futexes->list_lock);370 spinlock_lock(&TASK->futexes->list_lock); 369 371 list_append(&fut_ptr->all_link, &TASK->futexes->list); 370 mutex_unlock(&TASK->futexes->list_lock);372 spinlock_unlock(&TASK->futexes->list_lock); 371 373 } else { 372 374 /* Another thread of this task beat us to it. Use that mapping instead.*/ … … 398 400 return (sysarg_t) ENOENT; 399 401 400 #ifdef CONFIG_UDEBUG401 udebug_stoppable_begin();402 #endif403 402 int rc = waitq_sleep_timeout(&futex->wq, 0, SYNCH_FLAGS_INTERRUPTIBLE); 404 #ifdef CONFIG_UDEBUG 405 udebug_stoppable_end(); 406 #endif 403 407 404 return (sysarg_t) rc; 408 405 }
Note:
See TracChangeset
for help on using the changeset viewer.