]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/htl/pt-mutex-unlock.c
1 /* pthread_mutex_unlock. Hurd version.
2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
22 #include <pt-internal.h>
27 __pthread_mutex_unlock (pthread_mutex_t
*mtxp
)
29 struct __pthread
*self
;
30 int ret
= 0, flags
= mtxp
->__flags
& GSYNC_SHARED
;
32 switch (MTX_TYPE (mtxp
))
35 lll_unlock (&mtxp
->__lock
, flags
);
38 case PT_MTX_RECURSIVE
:
39 self
= _pthread_self ();
40 if (!mtx_owned_p (mtxp
, self
, flags
))
42 else if (--mtxp
->__cnt
== 0)
44 mtxp
->__owner_id
= mtxp
->__shpid
= 0;
45 lll_unlock (&mtxp
->__lock
, flags
);
50 case PT_MTX_ERRORCHECK
:
51 self
= _pthread_self ();
52 if (!mtx_owned_p (mtxp
, self
, flags
))
56 mtxp
->__owner_id
= mtxp
->__shpid
= 0;
57 lll_unlock (&mtxp
->__lock
, flags
);
62 case PT_MTX_NORMAL
| PTHREAD_MUTEX_ROBUST
:
63 case PT_MTX_RECURSIVE
| PTHREAD_MUTEX_ROBUST
:
64 case PT_MTX_ERRORCHECK
| PTHREAD_MUTEX_ROBUST
:
65 self
= _pthread_self ();
66 if (mtxp
->__owner_id
== NOTRECOVERABLE_ID
)
67 ; /* Nothing to do. */
68 else if (mtxp
->__owner_id
!= self
->thread
||
69 (int) (mtxp
->__lock
& LLL_OWNER_MASK
) != __getpid ())
71 else if (--mtxp
->__cnt
== 0)
73 /* Release the lock. If it's in an inconsistent
74 * state, mark it as irrecoverable. */
75 mtxp
->__owner_id
= (mtxp
->__lock
& LLL_DEAD_OWNER
) ?
76 NOTRECOVERABLE_ID
: 0;
77 __lll_robust_unlock (&mtxp
->__lock
, flags
);
90 strong_alias (__pthread_mutex_unlock
, _pthread_mutex_unlock
)
91 strong_alias (__pthread_mutex_unlock
, pthread_mutex_unlock
)