]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/x86/elision-lock.c
1 /* elision-lock.c: Elided pthread mutex lock.
2 Copyright (C) 2011-2015 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/>. */
21 #include "lowlevellock.h"
23 #include <elision-conf.h>
25 #if !defined(LLL_LOCK) && !defined(EXTRAARG)
26 /* Make sure the configuration code is always linked in for static
28 #include "elision-conf.c"
35 #define LLL_LOCK(a,b) lll_lock(a,b), 0
38 #define aconf __elision_aconf
40 /* Adaptive lock using transactions.
41 By default the lock region is run as a transaction, and when it
42 aborts or the lock is busy the lock adapts itself. */
45 __lll_lock_elision (int *futex
, short *adapt_count
, EXTRAARG
int private)
47 if (*adapt_count
<= 0)
52 for (try_xbegin
= aconf
.retry_try_xbegin
;
56 if ((status
= _xbegin()) == _XBEGIN_STARTED
)
61 /* Lock was busy. Fall back to normal locking.
62 Could also _xend here but xabort with 0xff code
63 is more visible in the profiler. */
64 _xabort (_ABORT_LOCK_BUSY
);
67 if (!(status
& _XABORT_RETRY
))
69 if ((status
& _XABORT_EXPLICIT
)
70 && _XABORT_CODE (status
) == _ABORT_LOCK_BUSY
)
72 /* Right now we skip here. Better would be to wait a bit
73 and retry. This likely needs some spinning. */
74 if (*adapt_count
!= aconf
.skip_lock_busy
)
75 *adapt_count
= aconf
.skip_lock_busy
;
77 /* Internal abort. There is no chance for retry.
78 Use the normal locking and next time use lock.
79 Be careful to avoid writing to the lock. */
80 else if (*adapt_count
!= aconf
.skip_lock_internal_abort
)
81 *adapt_count
= aconf
.skip_lock_internal_abort
;
88 /* Use a normal lock until the threshold counter runs out.
89 Lost updates possible. */
93 /* Use a normal lock here. */
94 return LLL_LOCK ((*futex
), private);