|
Packit Service |
82fcde |
/* Transfer ownership of a mutex. Generic version.
|
|
Packit Service |
82fcde |
Copyright (C) 2008-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
Written by Neal H. Walfield <neal@gnu.org>.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
This file is part of the GNU Hurd.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU Hurd is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
82fcde |
as published by the Free Software Foundation; either version 3 of
|
|
Packit Service |
82fcde |
the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU Hurd is distributed in the hope that it will be useful, but
|
|
Packit Service |
82fcde |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with this program. If not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <pthread.h>
|
|
Packit Service |
82fcde |
#include <assert.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <pt-internal.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
__pthread_mutex_transfer_np (struct __pthread_mutex *mutex, pthread_t tid)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
assert (mutex->__owner == _pthread_self ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
struct __pthread *thread = __pthread_getid (tid);
|
|
Packit Service |
82fcde |
const struct __pthread_mutexattr *attr = mutex->__attr;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (thread == NULL)
|
|
Packit Service |
82fcde |
return ESRCH;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (thread == _pthread_self ())
|
|
Packit Service |
82fcde |
return 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
|
|
Packit Service |
82fcde |
attr = &__pthread_errorcheck_mutexattr;
|
|
Packit Service |
82fcde |
if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
|
|
Packit Service |
82fcde |
attr = &__pthread_recursive_mutexattr;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (attr != NULL && attr->__mutex_type == PTHREAD_MUTEX_ERRORCHECK)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (mutex->__owner != _pthread_self ())
|
|
Packit Service |
82fcde |
return EPERM;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
mutex->__owner = thread;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifndef NDEBUG
|
|
Packit Service |
82fcde |
# if !defined(ALWAYS_TRACK_MUTEX_OWNER)
|
|
Packit Service |
82fcde |
if (attr != NULL && attr->__mutex_type != PTHREAD_MUTEX_NORMAL)
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
mutex->__owner = thread;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return 0;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
strong_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np)
|