|
Packit |
6c4009 |
/* __pthread_destory_specific. Hurd version.
|
|
Packit |
6c4009 |
Copyright (C) 2002-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <pthread.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <pt-internal.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
__pthread_destroy_specific (struct __pthread *thread)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int i;
|
|
Packit |
6c4009 |
int seen_one;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check if there is any thread specific data. */
|
|
Packit |
6c4009 |
if (thread->thread_specifics == NULL)
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__pthread_key_lock_ready ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Iterate and call the destructors on any thread specific data. */
|
|
Packit |
6c4009 |
for (;;)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
seen_one = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__pthread_mutex_lock (&__pthread_key_lock);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
for (i = 0; i < __pthread_key_count && i < thread->thread_specifics_size;
|
|
Packit |
6c4009 |
i++)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
void *value;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (__pthread_key_destructors[i] == PTHREAD_KEY_INVALID)
|
|
Packit |
6c4009 |
continue;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
value = thread->thread_specifics[i];
|
|
Packit |
6c4009 |
if (value != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
thread->thread_specifics[i] = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (__pthread_key_destructors[i])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
seen_one = 1;
|
|
Packit |
6c4009 |
__pthread_key_destructors[i] (value);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__pthread_mutex_unlock (&__pthread_key_lock);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (!seen_one)
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This may take a very long time. Let those blocking on
|
|
Packit |
6c4009 |
pthread_key_create or pthread_key_delete make progress. */
|
|
Packit |
6c4009 |
sched_yield ();
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
free (thread->thread_specifics);
|
|
Packit |
6c4009 |
thread->thread_specifics = 0;
|
|
Packit |
6c4009 |
thread->thread_specifics_size = 0;
|
|
Packit |
6c4009 |
}
|