1 /* pthread_mutex_transfer_np. Transfer mutex ownership to another thread.
3 Copyright (C) 2016-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
23 #include <pt-internal.h>
28 __pthread_mutex_transfer_np (pthread_mutex_t
*mtxp
, pthread_t th
)
30 struct __pthread
*self
= _pthread_self ();
31 struct __pthread
*pt
= __pthread_getid (th
);
39 int flags
= mtxp
->__flags
& GSYNC_SHARED
;
41 switch (MTX_TYPE (mtxp
))
46 case PT_MTX_RECURSIVE
:
47 case PT_MTX_ERRORCHECK
:
48 if (!mtx_owned_p (mtxp
, self
, flags
))
51 mtx_set_owner (mtxp
, pt
, flags
);
55 case PT_MTX_NORMAL
| PTHREAD_MUTEX_ROBUST
:
56 case PT_MTX_RECURSIVE
| PTHREAD_MUTEX_ROBUST
:
57 case PT_MTX_ERRORCHECK
| PTHREAD_MUTEX_ROBUST
:
58 /* Note that this can be used to transfer an inconsistent
59 * mutex as well. The new owner will still have the same
60 * flags as the original. */
61 if (mtxp
->__owner_id
!= self
->thread
62 || (int) (mtxp
->__lock
& LLL_OWNER_MASK
) != __getpid ())
65 mtxp
->__owner_id
= pt
->thread
;
76 weak_alias (__pthread_mutex_transfer_np
, pthread_mutex_transfer_np
)