Changeset a35b458 in mainline for kernel/generic/src/synch/futex.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/futex.c
r3061bc1 ra35b458 157 157 { 158 158 task->futexes = malloc(sizeof(struct futex_cache), 0); 159 159 160 160 cht_create(&task->futexes->ht, 0, 0, 0, true, &task_futex_ht_ops); 161 161 162 162 list_initialize(&task->futexes->list); 163 163 spinlock_initialize(&task->futexes->list_lock, "futex-list-lock"); … … 183 183 struct futex_cache *cache = 184 184 member_to_inst(work, struct futex_cache, destroy_work); 185 185 186 186 /* 187 187 * Destroy the cache before manually freeing items of the cache in case … … 189 189 */ 190 190 cht_destroy_unsafe(&cache->ht); 191 191 192 192 /* Manually free futex_ptr cache items. */ 193 193 list_foreach_safe(cache->list, cur_link, next_link) { … … 197 197 free(fut_ptr); 198 198 } 199 199 200 200 free(cache); 201 201 } … … 205 205 { 206 206 struct futex_cache *futexes = TASK->futexes; 207 207 208 208 /* All threads of this task have terminated. This is the last thread. */ 209 209 spinlock_lock(&futexes->list_lock); 210 210 211 211 list_foreach_safe(futexes->list, cur_link, next_link) { 212 212 futex_ptr_t *fut_ptr = member_to_inst(cur_link, futex_ptr_t, all_link); … … 222 222 futex_release_ref_locked(fut_ptr->futex); 223 223 } 224 224 225 225 spinlock_unlock(&futexes->list_lock); 226 226 } … … 252 252 assert(spinlock_locked(&futex_ht_lock)); 253 253 assert(0 < futex->refcount); 254 254 255 255 --futex->refcount; 256 256 257 257 if (0 == futex->refcount) { 258 258 hash_table_remove(&futex_ht, &futex->paddr); … … 272 272 { 273 273 futex_t *futex = find_cached_futex(uaddr); 274 274 275 275 if (futex) 276 276 return futex; … … 303 303 (uaddr - ALIGN_DOWN(uaddr, PAGE_SIZE)); 304 304 } 305 305 306 306 spinlock_unlock(&futex_ht_lock); 307 307 page_table_unlock(AS, false); 308 308 309 309 return success; 310 310 } … … 314 314 { 315 315 cht_read_lock(); 316 316 317 317 futex_t *futex; 318 318 cht_link_t *futex_ptr_link = cht_find_lazy(&TASK->futexes->ht, &uaddr); … … 321 321 futex_ptr_t *futex_ptr 322 322 = member_to_inst(futex_ptr_link, futex_ptr_t, cht_link); 323 323 324 324 futex = futex_ptr->futex; 325 325 } else { 326 326 futex = NULL; 327 327 } 328 328 329 329 cht_read_unlock(); 330 330 331 331 return futex; 332 332 } … … 340 340 { 341 341 futex_t *futex = malloc(sizeof(futex_t), 0); 342 342 343 343 /* 344 344 * Find the futex object in the global futex table (or insert it … … 346 346 */ 347 347 spinlock_lock(&futex_ht_lock); 348 348 349 349 ht_link_t *fut_link = hash_table_find(&futex_ht, &phys_addr); 350 350 351 351 if (fut_link) { 352 352 free(futex); … … 357 357 hash_table_insert(&futex_ht, &futex->ht_link); 358 358 } 359 359 360 360 spinlock_unlock(&futex_ht_lock); 361 361 362 362 /* 363 363 * Cache the link to the futex object for this task. … … 365 365 futex_ptr_t *fut_ptr = malloc(sizeof(futex_ptr_t), 0); 366 366 cht_link_t *dup_link; 367 367 368 368 fut_ptr->futex = futex; 369 369 fut_ptr->uaddr = uaddr; 370 370 371 371 cht_read_lock(); 372 372 373 373 /* Cache the mapping from the virtual address to the futex for this task. */ 374 374 if (cht_insert_unique(&TASK->futexes->ht, &fut_ptr->cht_link, &dup_link)) { … … 380 380 free(fut_ptr); 381 381 futex_release_ref_locked(futex); 382 382 383 383 futex_ptr_t *dup = member_to_inst(dup_link, futex_ptr_t, cht_link); 384 384 futex = dup->futex; … … 386 386 387 387 cht_read_unlock(); 388 388 389 389 return futex; 390 390 } … … 401 401 { 402 402 futex_t *futex = get_futex(uaddr); 403 403 404 404 if (!futex) 405 405 return (sys_errno_t) ENOENT; … … 428 428 { 429 429 futex_t *futex = get_futex(uaddr); 430 430 431 431 if (futex) { 432 432 waitq_wakeup(&futex->wq, WAKEUP_FIRST); … … 492 492 const futex_ptr_t *fut_ptr1 = member_to_inst(item1, futex_ptr_t, cht_link); 493 493 const futex_ptr_t *fut_ptr2 = member_to_inst(item2, futex_ptr_t, cht_link); 494 494 495 495 return fut_ptr1->uaddr == fut_ptr2->uaddr; 496 496 } … … 500 500 const futex_ptr_t *fut_ptr = member_to_inst(item, futex_ptr_t, cht_link); 501 501 uintptr_t uaddr = *(uintptr_t*)key; 502 502 503 503 return fut_ptr->uaddr == uaddr; 504 504 }
Note:
See TracChangeset
for help on using the changeset viewer.