Adds a destructor to the list.
| 69 | |
| 70 | // Adds a destructor to the list. |
| 71 | void AddDestructor(void (*destructor)(void*), void* arg) { |
| 72 | GoogleOnceInit(&once, &CreateKey); |
| 73 | |
| 74 | // Returns NULL if nothing is set yet. |
| 75 | std::unique_ptr<PerThreadDestructorList> p(new PerThreadDestructorList()); |
| 76 | p->destructor = destructor; |
| 77 | p->arg = arg; |
| 78 | p->next = reinterpret_cast<PerThreadDestructorList*>(pthread_getspecific(destructors_key)); |
| 79 | int ret = pthread_setspecific(destructors_key, p.release()); |
| 80 | // The only time this check should fail is if we are out of memory, or if |
| 81 | // somehow key creation failed, which should be caught by the above CHECK. |
| 82 | CHECK_EQ(0, ret) << "pthread_setspecific() failed, cannot update destructor list: " |
| 83 | << "error " << ret << ": " << ErrnoToString(ret); |
| 84 | } |
| 85 | |
| 86 | } // namespace internal |
| 87 | } // namespace threadlocal |
no test coverage detected