| 752 | } |
| 753 | |
| 754 | int bthread_id_list_reset2_pthreadsafe(bthread_id_list_t* list, |
| 755 | int error_code, |
| 756 | const std::string& error_text, |
| 757 | pthread_mutex_t* mutex) { |
| 758 | if (mutex == NULL) { |
| 759 | return EINVAL; |
| 760 | } |
| 761 | if (list->impl == NULL) { |
| 762 | return 0; |
| 763 | } |
| 764 | bthread_id_list_t tmplist; |
| 765 | const int rc = bthread_id_list_init(&tmplist, 0, 0); |
| 766 | if (rc != 0) { |
| 767 | return rc; |
| 768 | } |
| 769 | // Swap out the list then reset. The critical section is very small. |
| 770 | pthread_mutex_lock(mutex); |
| 771 | std::swap(list->impl, tmplist.impl); |
| 772 | pthread_mutex_unlock(mutex); |
| 773 | const int rc2 = bthread_id_list_reset2(&tmplist, error_code, error_text); |
| 774 | bthread_id_list_destroy(&tmplist); |
| 775 | return rc2; |
| 776 | } |
| 777 | |
| 778 | int bthread_id_list_reset2_bthreadsafe(bthread_id_list_t* list, |
| 779 | int error_code, |
no test coverage detected