pthread_key: when calling destructors, iterates over keys again

when a non-null value is found, up to PTHREAD_DESTRUCTOR_ITERATIONS (4).
* fixes LLVM unit test SanitizerCommon.PthreadDestructorIterations.
Change-Id: I1f9f4d3e8723261326e6e22b0f0d23907dccb59f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8979
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Jérôme Duval
2025-02-14 18:27:12 +00:00
committed by waddlesplash
parent 97a87f98c6
commit 64a0bc243c
@@ -63,13 +63,21 @@ get_key_value(pthread_thread* thread, uint32 key, int32 sequence)
void
__pthread_key_call_destructors(pthread_thread* thread)
{
for (uint32 key = 0; key < PTHREAD_KEYS_MAX; key++) {
int32 sequence;
pthread_key_destructor destructor = get_key_destructor(key, sequence);
void* value = get_key_value(thread, key, sequence);
for (uint32 iteration = 0; iteration < PTHREAD_DESTRUCTOR_ITERATIONS; iteration++) {
bool onlyNullValues = true;
for (uint32 key = 0; key < PTHREAD_KEYS_MAX; key++) {
int32 sequence;
pthread_key_destructor destructor = get_key_destructor(key, sequence);
void* value = get_key_value(thread, key, sequence);
if (value != NULL && destructor != NULL)
destructor(value);
if (value != NULL) {
onlyNullValues = false;
if (destructor != NULL)
destructor(value);
}
}
if (onlyNullValues)
break;
}
}