1 /* Transfer ownership of a mutex. Generic version.
2 Copyright (C) 2008-2020 Free Software Foundation, Inc.
3 Written by Neal H. Walfield <neal@gnu.org>.
5 This file is part of the GNU Hurd.
7 The GNU Hurd is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public License
9 as published by the Free Software Foundation; either version 3 of
10 the License, or (at your option) any later version.
12 The GNU Hurd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program. If not, see
19 <https://www.gnu.org/licenses/>. */
24 #include <pt-internal.h>
27 __pthread_mutex_transfer_np (struct __pthread_mutex
*mutex
, pthread_t tid
)
29 assert (mutex
->__owner
== _pthread_self ());
31 struct __pthread
*thread
= __pthread_getid (tid
);
32 const struct __pthread_mutexattr
*attr
= mutex
->__attr
;
37 if (thread
== _pthread_self ())
40 if (attr
== __PTHREAD_ERRORCHECK_MUTEXATTR
)
41 attr
= &__pthread_errorcheck_mutexattr
;
42 if (attr
== __PTHREAD_RECURSIVE_MUTEXATTR
)
43 attr
= &__pthread_recursive_mutexattr
;
45 if (attr
!= NULL
&& attr
->__mutex_type
== PTHREAD_MUTEX_ERRORCHECK
)
48 if (mutex
->__owner
!= _pthread_self ())
51 mutex
->__owner
= thread
;
55 # if !defined(ALWAYS_TRACK_MUTEX_OWNER)
56 if (attr
!= NULL
&& attr
->__mutex_type
!= PTHREAD_MUTEX_NORMAL
)
59 mutex
->__owner
= thread
;
66 strong_alias (__pthread_mutex_transfer_np
, pthread_mutex_transfer_np
)