Blame sysdeps/htl/pt-key.h

Packit 6c4009
/* pthread_key internal declatations for the 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 <libc-lockP.h>
Packit 6c4009
#include <pthreadP.h>
Packit 6c4009
Packit 6c4009
#define PTHREAD_KEY_MEMBERS \
Packit 6c4009
  void **thread_specifics;		/* This is only resized by the thread, and always growing */ \
Packit 6c4009
  unsigned thread_specifics_size;	/* Number of entries in thread_specifics */
Packit 6c4009
Packit 6c4009
#define PTHREAD_KEY_INVALID (void *) (-1)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with
Packit 6c4009
   __PTHREAD_KEY_SIZE elements.  If an element with index less than
Packit 6c4009
   __PTHREAD_KEY_COUNT is invalid, it shall contain the value
Packit 6c4009
   PTHREAD_KEY_INVALID which shall be distinct from NULL.
Packit 6c4009
Packit 6c4009
   Normally, we just add new keys to the end of the array and realloc
Packit 6c4009
   it as necessary.  The pthread_key_create routine may decide to
Packit 6c4009
   rescan the array if __PTHREAD_KEY_FREE is large.  */
Packit 6c4009
extern void (**__pthread_key_destructors) (void *arg);
Packit 6c4009
extern int __pthread_key_size;
Packit 6c4009
extern int __pthread_key_count;
Packit 6c4009
/* Number of invalid elements in the array.  Does not include elements
Packit 6c4009
   for which memory has been allocated but which have not yet been
Packit 6c4009
   used (i.e. those elements with indexes greater than
Packit 6c4009
   __PTHREAD_KEY_COUNT).  */
Packit 6c4009
extern int __pthread_key_invalid_count;
Packit 6c4009
Packit 6c4009
/* Protects the above variables.  This must be a recursive lock: the
Packit 6c4009
   destructors may call pthread_key_delete.  */
Packit 6c4009
extern pthread_mutex_t __pthread_key_lock;
Packit 6c4009

Packit 6c4009
#include <assert.h>
Packit 6c4009
Packit 6c4009
static inline void
Packit 6c4009
__pthread_key_lock_ready (void)
Packit 6c4009
{
Packit 6c4009
  static pthread_once_t o = PTHREAD_ONCE_INIT;
Packit 6c4009
Packit 6c4009
  void do_init (void)
Packit 6c4009
  {
Packit 6c4009
    int err;
Packit 6c4009
    pthread_mutexattr_t attr;
Packit 6c4009
Packit 6c4009
    err = __pthread_mutexattr_init (&attr);
Packit 6c4009
    assert_perror (err);
Packit 6c4009
Packit 6c4009
    err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
Packit 6c4009
    assert_perror (err);
Packit 6c4009
Packit 6c4009
    err = _pthread_mutex_init (&__pthread_key_lock, &attr);
Packit 6c4009
    assert_perror (err);
Packit 6c4009
Packit 6c4009
    err = __pthread_mutexattr_destroy (&attr);
Packit 6c4009
    assert_perror (err);
Packit 6c4009
  }
Packit 6c4009
Packit 6c4009
  __pthread_once (&o, do_init);
Packit 6c4009
}