| 515 | } |
| 516 | |
| 517 | static void |
| 518 | kcov_thread_dtor(void *arg __unused, struct thread *td) |
| 519 | { |
| 520 | struct kcov_info *info; |
| 521 | |
| 522 | info = td->td_kcov_info; |
| 523 | if (info == NULL) |
| 524 | return; |
| 525 | |
| 526 | mtx_lock_spin(&kcov_lock); |
| 527 | KASSERT(active_count > 0, ("%s: Open count is zero", __func__)); |
| 528 | active_count--; |
| 529 | if (active_count == 0) { |
| 530 | cov_unregister_pc(); |
| 531 | cov_unregister_cmp(); |
| 532 | } |
| 533 | td->td_kcov_info = NULL; |
| 534 | if (info->state != KCOV_STATE_DYING) { |
| 535 | /* |
| 536 | * The kcov file is still open. Mark it as unused and |
| 537 | * wait for it to be closed before cleaning up. |
| 538 | */ |
| 539 | atomic_store_int(&info->state, KCOV_STATE_READY); |
| 540 | atomic_thread_fence_seq_cst(); |
| 541 | /* This info struct is unused */ |
| 542 | info->thread = NULL; |
| 543 | mtx_unlock_spin(&kcov_lock); |
| 544 | return; |
| 545 | } |
| 546 | mtx_unlock_spin(&kcov_lock); |
| 547 | |
| 548 | /* |
| 549 | * We can safely clean up the info struct as it is in the |
| 550 | * KCOV_STATE_DYING state where the info struct is associated with |
| 551 | * the current thread that's about to exit. |
| 552 | * |
| 553 | * The KCOV_STATE_DYING stops new threads from using it. |
| 554 | * It also stops the current thread from trying to use the info struct. |
| 555 | */ |
| 556 | kcov_free(info); |
| 557 | } |
| 558 | |
| 559 | static void |
| 560 | kcov_init(const void *unused) |
nothing calls this directly
no test coverage detected