Blame htl/cthreads-compat.c

Packit 6c4009
/* Compatibility routines for cthreads.
Packit 6c4009
   Copyright (C) 2000-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 <assert.h>
Packit 6c4009
#include <pthreadP.h>
Packit 6c4009
Packit 6c4009
#define	CTHREAD_KEY_INVALID (__cthread_key_t) -1
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
__cthread_detach (__cthread_t thread)
Packit 6c4009
{
Packit 6c4009
  int err;
Packit 6c4009
Packit 6c4009
  err = __pthread_detach ((pthread_t) thread);
Packit 6c4009
  assert_perror (err);
Packit 6c4009
}
Packit 6c4009
weak_alias (__cthread_detach, cthread_detach)
Packit 6c4009
Packit 6c4009
__cthread_t
Packit 6c4009
__cthread_fork (__cthread_fn_t func, void *arg)
Packit 6c4009
{
Packit 6c4009
  pthread_t thread;
Packit 6c4009
  int err;
Packit 6c4009
Packit 6c4009
  err = __pthread_create (&thread, NULL, func, arg);
Packit 6c4009
  assert_perror (err);
Packit 6c4009
Packit 6c4009
  return (__cthread_t) thread;
Packit 6c4009
}
Packit 6c4009
weak_alias (__cthread_fork, cthread_fork)
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
__cthread_keycreate (__cthread_key_t *key)
Packit 6c4009
{
Packit 6c4009
  error_t err;
Packit 6c4009
Packit 6c4009
  err = __pthread_key_create (key, 0);
Packit 6c4009
  if (err)
Packit 6c4009
    {
Packit 6c4009
      errno = err;
Packit 6c4009
      *key = CTHREAD_KEY_INVALID;
Packit 6c4009
      err = -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return err;
Packit 6c4009
}
Packit 6c4009
weak_alias (__cthread_keycreate, cthread_keycreate)
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
__cthread_getspecific (__cthread_key_t key, void **val)
Packit 6c4009
{
Packit 6c4009
  *val = __pthread_getspecific (key);
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
weak_alias (__cthread_getspecific, cthread_getspecific)
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
__cthread_setspecific (__cthread_key_t key, void *val)
Packit 6c4009
{
Packit 6c4009
  error_t err;
Packit 6c4009
Packit 6c4009
  err = __pthread_setspecific (key, (const void *) val);
Packit 6c4009
  if (err)
Packit 6c4009
    {
Packit 6c4009
      errno = err;
Packit 6c4009
      err = -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return err;
Packit 6c4009
}
Packit 6c4009
weak_alias (__cthread_setspecific, cthread_setspecific)
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
__mutex_lock_solid (void *lock)
Packit 6c4009
{
Packit 6c4009
  __pthread_mutex_lock (lock);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
__mutex_unlock_solid (void *lock)
Packit 6c4009
{
Packit 6c4009
  if (__pthread_spin_trylock (lock) != 0)
Packit 6c4009
    /* Somebody already got the lock, that one will manage waking up others */
Packit 6c4009
    return;
Packit 6c4009
  __pthread_mutex_unlock (lock);
Packit 6c4009
}