2017-11-26 02:00:33 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2005-12-17 09:42:45 +00:00
|
|
|
* Copyright (C) 2005 Daniel M. Eischen <deischen@freebsd.org>
|
|
|
|
* Copyright (c) 2005 David Xu <davidxu@freebsd.org>
|
2003-04-01 03:46:29 +00:00
|
|
|
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
|
2005-12-17 09:42:45 +00:00
|
|
|
*
|
2003-04-01 03:46:29 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2005-12-17 09:42:45 +00:00
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
2003-04-01 03:46:29 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
2005-12-17 09:42:45 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2003-04-01 03:46:29 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _THR_PRIVATE_H
|
|
|
|
#define _THR_PRIVATE_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include files.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
2005-04-02 01:20:00 +00:00
|
|
|
#include <sys/cdefs.h>
|
2003-04-01 03:46:29 +00:00
|
|
|
#include <sys/queue.h>
|
2008-03-04 03:45:11 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/cpuset.h>
|
2005-04-02 01:20:00 +00:00
|
|
|
#include <machine/atomic.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2003-04-01 03:46:29 +00:00
|
|
|
#include <signal.h>
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
#include <stdbool.h>
|
2005-04-02 01:20:00 +00:00
|
|
|
#include <stddef.h>
|
2003-04-01 03:46:29 +00:00
|
|
|
#include <stdio.h>
|
2003-07-08 09:58:23 +00:00
|
|
|
#include <unistd.h>
|
2005-04-02 01:20:00 +00:00
|
|
|
#include <ucontext.h>
|
2003-04-01 03:46:29 +00:00
|
|
|
#include <sys/thr.h>
|
2005-04-02 01:20:00 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2017-01-28 20:54:43 +00:00
|
|
|
__NULLABILITY_PRAGMA_PUSH
|
|
|
|
|
Use umtx to implement process sharable semaphore, to make this work,
now type sema_t is a structure which can be put in a shared memory area,
and multiple processes can operate it concurrently.
User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open()
to initialize a shared semaphore.
Named semaphore uses file system and is located in /tmp directory, and its
file name is prefixed with 'SEMD', so now it is chroot or jail friendly.
In simplist cases, both for named and un-named semaphore, userland code
does not have to enter kernel to reduce/increase semaphore's count.
The semaphore is designed to be crash-safe, it means even if an application
is crashed in the middle of operating semaphore, the semaphore state is
still safely recovered by later use, there is no waiter counter maintained
by userland code.
The main semaphore code is in libc and libthr only has some necessary stubs,
this makes it possible that a non-threaded application can use semaphore
without linking to thread library.
Old semaphore implementation is kept libc to maintain binary compatibility.
The kernel ksem API is no longer used in the new implemenation.
Discussed on: threads@
2010-01-05 02:37:59 +00:00
|
|
|
#define SYM_FB10(sym) __CONCAT(sym, _fb10)
|
|
|
|
#define SYM_FBP10(sym) __CONCAT(sym, _fbp10)
|
|
|
|
#define WEAK_REF(sym, alias) __weak_reference(sym, alias)
|
|
|
|
#define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver)
|
|
|
|
#define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver)
|
|
|
|
|
|
|
|
#define FB10_COMPAT(func, sym) \
|
|
|
|
WEAK_REF(func, SYM_FB10(sym)); \
|
|
|
|
SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0)
|
|
|
|
|
|
|
|
#define FB10_COMPAT_PRIVATE(func, sym) \
|
|
|
|
WEAK_REF(func, SYM_FBP10(sym)); \
|
|
|
|
SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0)
|
|
|
|
|
2017-05-26 15:56:28 +00:00
|
|
|
struct pthread;
|
|
|
|
extern struct pthread *_thr_initial __hidden;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#include "pthread_md.h"
|
|
|
|
#include "thr_umtx.h"
|
2005-04-12 03:00:28 +00:00
|
|
|
#include "thread_db.h"
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2010-09-15 02:56:32 +00:00
|
|
|
#ifdef _PTHREAD_FORCED_UNWIND
|
2010-09-30 12:59:56 +00:00
|
|
|
#define _BSD_SOURCE
|
|
|
|
#include <unwind.h>
|
2010-09-15 02:56:32 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-21 03:14:06 +00:00
|
|
|
typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist;
|
|
|
|
typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
|
2006-08-28 04:52:50 +00:00
|
|
|
TAILQ_HEAD(mutex_queue, pthread_mutex);
|
2003-12-09 11:20:01 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Signal to do cancellation */
|
2012-04-18 16:29:55 +00:00
|
|
|
#define SIGCANCEL SIGTHR
|
2003-12-09 11:20:01 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/*
|
|
|
|
* Kernel fatal error handler macro.
|
|
|
|
*/
|
2016-06-01 16:09:56 +00:00
|
|
|
#define PANIC(args...) _thread_exitf(__FILE__, __LINE__, ##args)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/* Output debug messages like this: */
|
2005-04-02 01:20:00 +00:00
|
|
|
#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
|
2007-08-07 04:50:14 +00:00
|
|
|
#define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#ifdef _PTHREADS_INVARIANTS
|
|
|
|
#define THR_ASSERT(cond, msg) do { \
|
|
|
|
if (__predict_false(!(cond))) \
|
|
|
|
PANIC(msg); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define THR_ASSERT(cond, msg)
|
|
|
|
#endif
|
2003-04-02 03:05:39 +00:00
|
|
|
|
2014-11-25 03:50:31 +00:00
|
|
|
#ifdef PIC
|
2006-01-10 04:53:03 +00:00
|
|
|
# define STATIC_LIB_REQUIRE(name)
|
|
|
|
#else
|
|
|
|
# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name)
|
|
|
|
#endif
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define TIMESPEC_ADD(dst, src, val) \
|
|
|
|
do { \
|
|
|
|
(dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \
|
|
|
|
(dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \
|
2005-06-22 22:38:56 +00:00
|
|
|
if ((dst)->tv_nsec >= 1000000000) { \
|
2005-04-02 01:20:00 +00:00
|
|
|
(dst)->tv_sec++; \
|
|
|
|
(dst)->tv_nsec -= 1000000000; \
|
|
|
|
} \
|
2003-06-29 23:49:41 +00:00
|
|
|
} while (0)
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define TIMESPEC_SUB(dst, src, val) \
|
|
|
|
do { \
|
|
|
|
(dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
|
|
|
|
(dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
|
|
|
|
if ((dst)->tv_nsec < 0) { \
|
|
|
|
(dst)->tv_sec--; \
|
|
|
|
(dst)->tv_nsec += 1000000000; \
|
|
|
|
} \
|
2003-07-06 10:10:32 +00:00
|
|
|
} while (0)
|
2003-06-29 23:49:41 +00:00
|
|
|
|
2016-02-28 17:52:33 +00:00
|
|
|
/* Magic cookie set for shared pthread locks and cv's pointers */
|
|
|
|
#define THR_PSHARED_PTR \
|
|
|
|
((void *)(uintptr_t)((1ULL << (NBBY * sizeof(long) - 1)) | 1))
|
|
|
|
|
2010-09-28 04:57:56 +00:00
|
|
|
/* XXX These values should be same as those defined in pthread.h */
|
|
|
|
#define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL)
|
|
|
|
#define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1)
|
|
|
|
#define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2)
|
|
|
|
#define THR_COND_INITIALIZER ((struct pthread_cond *)NULL)
|
|
|
|
#define THR_COND_DESTROYED ((struct pthread_cond *)1)
|
|
|
|
#define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL)
|
|
|
|
#define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1)
|
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
#define PMUTEX_FLAG_TYPE_MASK 0x0ff
|
|
|
|
#define PMUTEX_FLAG_PRIVATE 0x100
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
#define PMUTEX_FLAG_DEFERRED 0x200
|
2010-12-22 05:01:52 +00:00
|
|
|
#define PMUTEX_TYPE(mtxflags) ((mtxflags) & PMUTEX_FLAG_TYPE_MASK)
|
|
|
|
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
#define PMUTEX_OWNER_ID(m) ((m)->m_lock.m_owner & ~UMUTEX_CONTESTED)
|
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
#define MAX_DEFER_WAITERS 50
|
|
|
|
|
2016-03-22 10:51:42 +00:00
|
|
|
/*
|
|
|
|
* Values for pthread_mutex m_ps indicator.
|
|
|
|
*/
|
|
|
|
#define PMUTEX_INITSTAGE_ALLOC 0
|
|
|
|
#define PMUTEX_INITSTAGE_BUSY 1
|
|
|
|
#define PMUTEX_INITSTAGE_DONE 2
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
struct pthread_mutex {
|
|
|
|
/*
|
|
|
|
* Lock for accesses to this structure.
|
|
|
|
*/
|
2006-08-28 04:52:50 +00:00
|
|
|
struct umutex m_lock;
|
2010-12-22 05:01:52 +00:00
|
|
|
int m_flags;
|
2005-04-02 01:20:00 +00:00
|
|
|
int m_count;
|
2007-12-14 06:25:57 +00:00
|
|
|
int m_spinloops;
|
|
|
|
int m_yieldloops;
|
2016-03-22 10:51:42 +00:00
|
|
|
int m_ps; /* pshared init stage */
|
2005-04-02 01:20:00 +00:00
|
|
|
/*
|
2016-02-28 17:52:33 +00:00
|
|
|
* Link for all mutexes a thread currently owns, of the same
|
|
|
|
* prio type.
|
2005-04-02 01:20:00 +00:00
|
|
|
*/
|
|
|
|
TAILQ_ENTRY(pthread_mutex) m_qe;
|
2016-02-28 17:52:33 +00:00
|
|
|
/* Link for all private mutexes a thread currently owns. */
|
|
|
|
TAILQ_ENTRY(pthread_mutex) m_pqe;
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
struct pthread_mutex *m_rb_prev;
|
2005-04-02 01:20:00 +00:00
|
|
|
};
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
struct pthread_mutex_attr {
|
|
|
|
enum pthread_mutextype m_type;
|
|
|
|
int m_protocol;
|
|
|
|
int m_ceiling;
|
2016-02-28 17:52:33 +00:00
|
|
|
int m_pshared;
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
int m_robust;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
{ PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE, \
|
|
|
|
PTHREAD_MUTEX_STALLED }
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
struct pthread_cond {
|
2010-12-22 05:01:52 +00:00
|
|
|
__uint32_t __has_user_waiters;
|
2016-05-29 19:35:55 +00:00
|
|
|
struct ucond kcond;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_cond_attr {
|
2005-04-02 01:20:00 +00:00
|
|
|
int c_pshared;
|
|
|
|
int c_clockid;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
struct pthread_barrier {
|
2006-12-05 06:54:25 +00:00
|
|
|
struct umutex b_lock;
|
|
|
|
struct ucond b_cv;
|
2012-03-16 04:35:52 +00:00
|
|
|
int64_t b_cycle;
|
|
|
|
int b_count;
|
|
|
|
int b_waiters;
|
|
|
|
int b_refcount;
|
|
|
|
int b_destroying;
|
2005-04-02 01:20:00 +00:00
|
|
|
};
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
struct pthread_barrierattr {
|
|
|
|
int pshared;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_spinlock {
|
2006-09-06 04:04:10 +00:00
|
|
|
struct umutex s_lock;
|
2005-04-02 01:20:00 +00:00
|
|
|
};
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
2005-04-02 01:20:00 +00:00
|
|
|
* Flags for condition variables.
|
2003-04-01 03:46:29 +00:00
|
|
|
*/
|
2005-04-02 01:20:00 +00:00
|
|
|
#define COND_FLAGS_PRIVATE 0x01
|
|
|
|
#define COND_FLAGS_INITED 0x02
|
|
|
|
#define COND_FLAGS_BUSY 0x04
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup definitions.
|
|
|
|
*/
|
|
|
|
struct pthread_cleanup {
|
2008-06-09 01:14:10 +00:00
|
|
|
struct pthread_cleanup *prev;
|
|
|
|
void (*routine)(void *);
|
2003-04-01 03:46:29 +00:00
|
|
|
void *routine_arg;
|
2008-06-09 01:14:10 +00:00
|
|
|
int onheap;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_CLEANUP_PUSH(td, func, arg) { \
|
|
|
|
struct pthread_cleanup __cup; \
|
|
|
|
\
|
|
|
|
__cup.routine = func; \
|
|
|
|
__cup.routine_arg = arg; \
|
2008-06-09 01:14:10 +00:00
|
|
|
__cup.onheap = 0; \
|
|
|
|
__cup.prev = (td)->cleanup; \
|
2005-04-02 01:20:00 +00:00
|
|
|
(td)->cleanup = &__cup;
|
|
|
|
|
|
|
|
#define THR_CLEANUP_POP(td, exec) \
|
2008-06-09 01:14:10 +00:00
|
|
|
(td)->cleanup = __cup.prev; \
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((exec) != 0) \
|
|
|
|
__cup.routine(__cup.routine_arg); \
|
|
|
|
}
|
|
|
|
|
2004-06-27 10:01:35 +00:00
|
|
|
struct pthread_atfork {
|
|
|
|
TAILQ_ENTRY(pthread_atfork) qe;
|
|
|
|
void (*prepare)(void);
|
|
|
|
void (*parent)(void);
|
|
|
|
void (*child)(void);
|
|
|
|
};
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
struct pthread_attr {
|
2010-10-25 09:16:04 +00:00
|
|
|
#define pthread_attr_start_copy sched_policy
|
2003-04-01 03:46:29 +00:00
|
|
|
int sched_policy;
|
|
|
|
int sched_inherit;
|
|
|
|
int prio;
|
|
|
|
int suspend;
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
|
2003-04-01 03:46:29 +00:00
|
|
|
int flags;
|
|
|
|
void *stackaddr_attr;
|
|
|
|
size_t stacksize_attr;
|
|
|
|
size_t guardsize_attr;
|
2010-10-25 09:16:04 +00:00
|
|
|
#define pthread_attr_end_copy cpuset
|
2008-03-04 03:03:24 +00:00
|
|
|
cpuset_t *cpuset;
|
|
|
|
size_t cpusetsize;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
struct wake_addr {
|
|
|
|
struct wake_addr *link;
|
|
|
|
unsigned int value;
|
|
|
|
char pad[12];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sleepqueue {
|
|
|
|
TAILQ_HEAD(, pthread) sq_blocked;
|
|
|
|
SLIST_HEAD(, sleepqueue) sq_freeq;
|
|
|
|
LIST_ENTRY(sleepqueue) sq_hash;
|
|
|
|
SLIST_ENTRY(sleepqueue) sq_flink;
|
|
|
|
void *sq_wchan;
|
|
|
|
int sq_type;
|
|
|
|
};
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
/*
|
|
|
|
* Thread creation state attributes.
|
|
|
|
*/
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_CREATE_RUNNING 0
|
|
|
|
#define THR_CREATE_SUSPENDED 1
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous definitions.
|
|
|
|
*/
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024)
|
2005-03-06 07:56:18 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
/*
|
|
|
|
* Maximum size of initial thread's stack. This perhaps deserves to be larger
|
|
|
|
* than the stacks of other threads, since many applications are likely to run
|
|
|
|
* almost entirely on this stack.
|
|
|
|
*/
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
2006-04-27 08:18:23 +00:00
|
|
|
* Define priorities returned by kernel.
|
2003-04-01 03:46:29 +00:00
|
|
|
*/
|
2006-04-27 08:18:23 +00:00
|
|
|
#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
|
2006-07-12 06:13:18 +00:00
|
|
|
#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max)
|
2006-04-27 08:18:23 +00:00
|
|
|
#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default)
|
|
|
|
|
|
|
|
#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min)
|
|
|
|
#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max)
|
|
|
|
#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default)
|
|
|
|
|
|
|
|
/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
|
|
|
|
#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min)
|
2006-07-12 06:13:18 +00:00
|
|
|
#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max)
|
2006-04-27 08:18:23 +00:00
|
|
|
#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default)
|
|
|
|
|
|
|
|
struct pthread_prio {
|
|
|
|
int pri_min;
|
|
|
|
int pri_max;
|
|
|
|
int pri_default;
|
|
|
|
};
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
struct pthread_rwlockattr {
|
|
|
|
int pshared;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_rwlock {
|
2008-04-02 04:32:31 +00:00
|
|
|
struct urwlock lock;
|
2016-02-28 17:52:33 +00:00
|
|
|
uint32_t owner;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Thread states.
|
|
|
|
*/
|
|
|
|
enum pthread_state {
|
|
|
|
PS_RUNNING,
|
2005-04-02 01:20:00 +00:00
|
|
|
PS_DEAD
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_specific_elem {
|
|
|
|
const void *data;
|
|
|
|
int seqno;
|
|
|
|
};
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
struct pthread_key {
|
|
|
|
volatile int allocated;
|
|
|
|
int seqno;
|
|
|
|
void (*destructor)(void *);
|
2004-01-19 14:51:45 +00:00
|
|
|
};
|
|
|
|
|
2006-08-28 04:52:50 +00:00
|
|
|
/*
|
|
|
|
* lwpid_t is 32bit but kernel thr API exports tid as long type
|
2015-03-09 20:26:42 +00:00
|
|
|
* to preserve the ABI for M:N model in very early date (r131431).
|
2006-08-28 04:52:50 +00:00
|
|
|
*/
|
|
|
|
#define TID(thread) ((uint32_t) ((thread)->tid))
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
/*
|
|
|
|
* Thread structure.
|
|
|
|
*/
|
|
|
|
struct pthread {
|
2012-02-07 02:57:36 +00:00
|
|
|
#define _pthread_startzero tid
|
2006-03-27 23:50:21 +00:00
|
|
|
/* Kernel thread id. */
|
|
|
|
long tid;
|
|
|
|
#define TID_TERMINATED 1
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock for accesses to this thread structure.
|
|
|
|
*/
|
2006-09-06 04:04:10 +00:00
|
|
|
struct umutex lock;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
/* Internal condition variable cycle number. */
|
2008-04-29 03:58:18 +00:00
|
|
|
uint32_t cycle;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
/* How many low level locks the thread held. */
|
|
|
|
int locklevel;
|
|
|
|
|
2006-01-05 13:51:22 +00:00
|
|
|
/*
|
|
|
|
* Set to non-zero when this thread has entered a critical
|
|
|
|
* region. We allow for recursive entries into critical regions.
|
|
|
|
*/
|
|
|
|
int critical_count;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Signal blocked counter. */
|
|
|
|
int sigblock;
|
|
|
|
|
2020-02-09 12:27:22 +00:00
|
|
|
/* Fast sigblock var. */
|
|
|
|
uint32_t fsigblock;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Queue entry for list of all threads. */
|
|
|
|
TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
|
|
|
|
|
|
|
|
/* Queue entry for GC lists. */
|
|
|
|
TAILQ_ENTRY(pthread) gcle;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Hash queue entry. */
|
|
|
|
LIST_ENTRY(pthread) hle;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
/* Sleep queue entry */
|
|
|
|
TAILQ_ENTRY(pthread) wle;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Threads reference count. */
|
|
|
|
int refcount;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Thread start routine, argument, stack pointer and thread
|
|
|
|
* attributes.
|
|
|
|
*/
|
|
|
|
void *(*start_routine)(void *);
|
|
|
|
void *arg;
|
|
|
|
struct pthread_attr attr;
|
|
|
|
|
2006-11-24 09:57:38 +00:00
|
|
|
#define SHOULD_CANCEL(thr) \
|
2010-09-19 09:03:11 +00:00
|
|
|
((thr)->cancel_pending && (thr)->cancel_enable && \
|
|
|
|
(thr)->no_cancel == 0)
|
2006-11-24 09:57:38 +00:00
|
|
|
|
|
|
|
/* Cancellation is enabled */
|
|
|
|
int cancel_enable;
|
|
|
|
|
|
|
|
/* Cancellation request is pending */
|
|
|
|
int cancel_pending;
|
|
|
|
|
|
|
|
/* Thread is at cancellation point */
|
|
|
|
int cancel_point;
|
|
|
|
|
2010-09-19 09:03:11 +00:00
|
|
|
/* Cancellation is temporarily disabled */
|
|
|
|
int no_cancel;
|
2006-12-04 14:20:41 +00:00
|
|
|
|
2006-11-24 09:57:38 +00:00
|
|
|
/* Asynchronouse cancellation is enabled */
|
|
|
|
int cancel_async;
|
|
|
|
|
|
|
|
/* Cancellation is in progress */
|
|
|
|
int cancelling;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
/* Thread temporary signal mask. */
|
|
|
|
sigset_t sigmask;
|
|
|
|
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
/* Thread should unblock SIGCANCEL. */
|
2008-03-04 04:28:59 +00:00
|
|
|
int unblock_sigcancel;
|
|
|
|
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
/* In sigsuspend state */
|
|
|
|
int in_sigsuspend;
|
|
|
|
|
|
|
|
/* deferred signal info */
|
|
|
|
siginfo_t deferred_siginfo;
|
|
|
|
|
|
|
|
/* signal mask to restore. */
|
|
|
|
sigset_t deferred_sigmask;
|
|
|
|
|
|
|
|
/* the sigaction should be used for deferred signal. */
|
|
|
|
struct sigaction deferred_sigact;
|
|
|
|
|
2013-11-23 15:48:17 +00:00
|
|
|
/* deferred signal delivery is performed, do not reenter. */
|
|
|
|
int deferred_run;
|
|
|
|
|
2008-03-05 07:01:20 +00:00
|
|
|
/* Force new thread to exit. */
|
|
|
|
int force_exit;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Thread state: */
|
2006-10-13 12:45:21 +00:00
|
|
|
enum pthread_state state;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Error variable used instead of errno. The function __error()
|
|
|
|
* returns a pointer to this.
|
|
|
|
*/
|
2005-04-02 01:20:00 +00:00
|
|
|
int error;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The joiner is the thread that is joining to this thread. The
|
|
|
|
* join status keeps track of a join operation to another thread.
|
|
|
|
*/
|
|
|
|
struct pthread *joiner;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Miscellaneous flags; only set with scheduling lock held. */
|
|
|
|
int flags;
|
|
|
|
#define THR_FLAGS_PRIVATE 0x0001
|
|
|
|
#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */
|
|
|
|
#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */
|
2010-09-15 01:21:30 +00:00
|
|
|
#define THR_FLAGS_DETACHED 0x0008 /* thread is detached */
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
/* Thread list flags; only set with thread list lock held. */
|
|
|
|
int tlflags;
|
|
|
|
#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */
|
|
|
|
#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */
|
2010-09-15 01:21:30 +00:00
|
|
|
#define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2016-02-28 17:52:33 +00:00
|
|
|
/*
|
|
|
|
* Queues of the owned mutexes. Private queue must have index
|
|
|
|
* + 1 of the corresponding full queue.
|
|
|
|
*/
|
|
|
|
#define TMQ_NORM 0 /* NORMAL or PRIO_INHERIT normal */
|
|
|
|
#define TMQ_NORM_PRIV 1 /* NORMAL or PRIO_INHERIT normal priv */
|
|
|
|
#define TMQ_NORM_PP 2 /* PRIO_PROTECT normal mutexes */
|
|
|
|
#define TMQ_NORM_PP_PRIV 3 /* PRIO_PROTECT normal priv */
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
#define TMQ_ROBUST_PP 4 /* PRIO_PROTECT robust mutexes */
|
|
|
|
#define TMQ_ROBUST_PP_PRIV 5 /* PRIO_PROTECT robust priv */
|
|
|
|
#define TMQ_NITEMS 6
|
2016-02-28 17:52:33 +00:00
|
|
|
struct mutex_queue mq[TMQ_NITEMS];
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
void *ret;
|
|
|
|
struct pthread_specific_elem *specific;
|
|
|
|
int specific_data_count;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Number rwlocks rdlocks held. */
|
|
|
|
int rdlock_count;
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
/*
|
2005-04-02 01:20:00 +00:00
|
|
|
* Current locks bitmap for rtld. */
|
|
|
|
int rtld_bits;
|
|
|
|
|
|
|
|
/* Thread control block */
|
|
|
|
struct tcb *tcb;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/* Cleanup handlers Link List */
|
2005-04-02 01:20:00 +00:00
|
|
|
struct pthread_cleanup *cleanup;
|
2005-04-12 03:00:28 +00:00
|
|
|
|
2010-09-15 02:56:32 +00:00
|
|
|
#ifdef _PTHREAD_FORCED_UNWIND
|
|
|
|
struct _Unwind_Exception ex;
|
|
|
|
void *unwind_stackend;
|
2010-09-25 08:36:46 +00:00
|
|
|
int unwind_disabled;
|
2010-09-15 02:56:32 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-27 23:50:21 +00:00
|
|
|
/*
|
|
|
|
* Magic value to help recognize a valid thread structure
|
|
|
|
* from an invalid one:
|
|
|
|
*/
|
|
|
|
#define THR_MAGIC ((u_int32_t) 0xd09ba115)
|
|
|
|
u_int32_t magic;
|
|
|
|
|
2005-04-12 03:00:28 +00:00
|
|
|
/* Enable event reporting */
|
|
|
|
int report_events;
|
|
|
|
|
|
|
|
/* Event mask */
|
|
|
|
int event_mask;
|
|
|
|
|
|
|
|
/* Event */
|
|
|
|
td_event_msg_t event_buf;
|
2010-12-22 05:01:52 +00:00
|
|
|
|
|
|
|
/* Wait channel */
|
|
|
|
void *wchan;
|
|
|
|
|
|
|
|
/* Referenced mutex. */
|
|
|
|
struct pthread_mutex *mutex_obj;
|
|
|
|
|
|
|
|
/* Thread will sleep. */
|
|
|
|
int will_sleep;
|
|
|
|
|
|
|
|
/* Number of threads deferred. */
|
|
|
|
int nwaiter_defer;
|
|
|
|
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
int robust_inited;
|
|
|
|
uintptr_t robust_list;
|
|
|
|
uintptr_t priv_robust_list;
|
|
|
|
uintptr_t inact_mtx;
|
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
/* Deferred threads from pthread_cond_signal. */
|
|
|
|
unsigned int *defer_waiters[MAX_DEFER_WAITERS];
|
2012-02-07 02:57:36 +00:00
|
|
|
#define _pthread_endzero wake_addr
|
|
|
|
|
|
|
|
struct wake_addr *wake_addr;
|
|
|
|
#define WAKE_ADDR(td) ((td)->wake_addr)
|
|
|
|
|
|
|
|
/* Sleep queue */
|
|
|
|
struct sleepqueue *sleepqueue;
|
|
|
|
|
2018-08-17 18:34:07 +00:00
|
|
|
/* pthread_set/get_name_np */
|
|
|
|
char *name;
|
2021-04-07 22:02:33 +00:00
|
|
|
|
|
|
|
/* rtld thread-local dlerror message and seen control */
|
|
|
|
char dlerror_msg[512];
|
|
|
|
int dlerror_seen;
|
2003-04-01 03:46:29 +00:00
|
|
|
};
|
|
|
|
|
2010-09-13 07:03:01 +00:00
|
|
|
#define THR_SHOULD_GC(thrd) \
|
|
|
|
((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \
|
|
|
|
((thrd)->flags & THR_FLAGS_DETACHED) != 0)
|
|
|
|
|
2006-01-05 13:51:22 +00:00
|
|
|
#define THR_IN_CRITICAL(thrd) \
|
|
|
|
(((thrd)->locklevel > 0) || \
|
|
|
|
((thrd)->critical_count > 0))
|
|
|
|
|
2006-03-25 04:49:07 +00:00
|
|
|
#define THR_CRITICAL_ENTER(thrd) \
|
|
|
|
(thrd)->critical_count++
|
|
|
|
|
|
|
|
#define THR_CRITICAL_LEAVE(thrd) \
|
2008-04-03 02:47:35 +00:00
|
|
|
do { \
|
|
|
|
(thrd)->critical_count--; \
|
|
|
|
_thr_ast(thrd); \
|
|
|
|
} while (0)
|
2006-03-25 04:49:07 +00:00
|
|
|
|
2006-09-06 04:04:10 +00:00
|
|
|
#define THR_UMUTEX_TRYLOCK(thrd, lck) \
|
|
|
|
_thr_umutex_trylock((lck), TID(thrd))
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2006-09-06 04:04:10 +00:00
|
|
|
#define THR_UMUTEX_LOCK(thrd, lck) \
|
|
|
|
_thr_umutex_lock((lck), TID(thrd))
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2006-09-06 04:04:10 +00:00
|
|
|
#define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \
|
|
|
|
_thr_umutex_timedlock((lck), TID(thrd), (timo))
|
2003-05-26 00:37:07 +00:00
|
|
|
|
2006-09-06 04:04:10 +00:00
|
|
|
#define THR_UMUTEX_UNLOCK(thrd, lck) \
|
|
|
|
_thr_umutex_unlock((lck), TID(thrd))
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_LOCK_ACQUIRE(thrd, lck) \
|
|
|
|
do { \
|
|
|
|
(thrd)->locklevel++; \
|
2006-09-06 04:04:10 +00:00
|
|
|
_thr_umutex_lock(lck, TID(thrd)); \
|
2005-04-02 01:20:00 +00:00
|
|
|
} while (0)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
#define THR_LOCK_ACQUIRE_SPIN(thrd, lck) \
|
|
|
|
do { \
|
|
|
|
(thrd)->locklevel++; \
|
|
|
|
_thr_umutex_lock_spin(lck, TID(thrd)); \
|
|
|
|
} while (0)
|
|
|
|
|
2006-01-09 07:32:22 +00:00
|
|
|
#ifdef _PTHREADS_INVARIANTS
|
|
|
|
#define THR_ASSERT_LOCKLEVEL(thrd) \
|
2005-04-02 01:20:00 +00:00
|
|
|
do { \
|
2006-01-09 07:32:22 +00:00
|
|
|
if (__predict_false((thrd)->locklevel <= 0)) \
|
2005-04-02 01:20:00 +00:00
|
|
|
_thr_assert_lock_level(); \
|
2006-01-09 07:32:22 +00:00
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define THR_ASSERT_LOCKLEVEL(thrd)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define THR_LOCK_RELEASE(thrd, lck) \
|
|
|
|
do { \
|
|
|
|
THR_ASSERT_LOCKLEVEL(thrd); \
|
2006-09-06 04:04:10 +00:00
|
|
|
_thr_umutex_unlock((lck), TID(thrd)); \
|
2006-01-09 07:32:22 +00:00
|
|
|
(thrd)->locklevel--; \
|
|
|
|
_thr_ast(thrd); \
|
2005-04-02 01:20:00 +00:00
|
|
|
} while (0)
|
2003-05-25 08:31:33 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock)
|
|
|
|
#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock)
|
|
|
|
#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
|
|
|
|
#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
|
2003-05-25 08:31:33 +00:00
|
|
|
|
2010-09-13 07:03:01 +00:00
|
|
|
#define THREAD_LIST_RDLOCK(curthrd) \
|
|
|
|
do { \
|
|
|
|
(curthrd)->locklevel++; \
|
|
|
|
_thr_rwl_rdlock(&_thr_list_lock); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define THREAD_LIST_WRLOCK(curthrd) \
|
2005-04-02 01:20:00 +00:00
|
|
|
do { \
|
2010-09-13 07:03:01 +00:00
|
|
|
(curthrd)->locklevel++; \
|
|
|
|
_thr_rwl_wrlock(&_thr_list_lock); \
|
2005-04-02 01:20:00 +00:00
|
|
|
} while (0)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define THREAD_LIST_UNLOCK(curthrd) \
|
|
|
|
do { \
|
2010-09-13 07:03:01 +00:00
|
|
|
_thr_rwl_unlock(&_thr_list_lock); \
|
|
|
|
(curthrd)->locklevel--; \
|
|
|
|
_thr_ast(curthrd); \
|
2005-04-02 01:20:00 +00:00
|
|
|
} while (0)
|
2004-06-27 10:01:35 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/*
|
|
|
|
* Macros to insert/remove threads to the all thread list and
|
|
|
|
* the gc list.
|
|
|
|
*/
|
|
|
|
#define THR_LIST_ADD(thrd) do { \
|
|
|
|
if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \
|
|
|
|
TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
|
|
|
|
_thr_hash_add(thrd); \
|
|
|
|
(thrd)->tlflags |= TLFLAGS_IN_TDLIST; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define THR_LIST_REMOVE(thrd) do { \
|
|
|
|
if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \
|
|
|
|
TAILQ_REMOVE(&_thread_list, thrd, tle); \
|
|
|
|
_thr_hash_remove(thrd); \
|
|
|
|
(thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define THR_GCLIST_ADD(thrd) do { \
|
2010-09-15 01:21:30 +00:00
|
|
|
if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \
|
2005-04-02 01:20:00 +00:00
|
|
|
TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
|
2010-09-15 01:21:30 +00:00
|
|
|
(thrd)->tlflags |= TLFLAGS_IN_GCLIST; \
|
2005-04-02 01:20:00 +00:00
|
|
|
_gc_count++; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define THR_GCLIST_REMOVE(thrd) do { \
|
2010-09-15 01:21:30 +00:00
|
|
|
if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \
|
2005-04-02 01:20:00 +00:00
|
|
|
TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
|
2010-09-15 01:21:30 +00:00
|
|
|
(thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \
|
2005-04-02 01:20:00 +00:00
|
|
|
_gc_count--; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2010-09-13 07:03:01 +00:00
|
|
|
#define THR_REF_ADD(curthread, pthread) { \
|
|
|
|
THR_CRITICAL_ENTER(curthread); \
|
|
|
|
pthread->refcount++; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define THR_REF_DEL(curthread, pthread) { \
|
|
|
|
pthread->refcount--; \
|
|
|
|
THR_CRITICAL_LEAVE(curthread); \
|
|
|
|
} while (0)
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#define GC_NEEDED() (_gc_count >= 5)
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-12 03:00:28 +00:00
|
|
|
#define SHOULD_REPORT_EVENT(curthr, e) \
|
|
|
|
(curthr->report_events && \
|
|
|
|
(((curthr)->event_mask | _thread_event_mask ) & e) != 0)
|
|
|
|
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef __LIBC_ISTHREADED_DECLARED
|
|
|
|
#define __LIBC_ISTHREADED_DECLARED
|
2005-04-02 01:20:00 +00:00
|
|
|
extern int __isthreaded;
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
2005-04-02 01:20:00 +00:00
|
|
|
* Global variables for the pthread kernel.
|
2003-04-01 03:46:29 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-04 02:57:49 +00:00
|
|
|
extern char *_usrstack __hidden;
|
2005-04-12 03:00:28 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* For debugger */
|
2005-12-21 03:14:06 +00:00
|
|
|
extern int _libthr_debug;
|
|
|
|
extern int _thread_event_mask;
|
|
|
|
extern struct pthread *_thread_last_event;
|
2017-10-02 20:33:16 +00:00
|
|
|
/* Used in symbol lookup of libthread_db */
|
|
|
|
extern struct pthread_key _thread_keytable[];
|
2003-06-29 15:55:44 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* List of all threads: */
|
2005-12-21 03:14:06 +00:00
|
|
|
extern pthreadlist _thread_list;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* List of threads needing GC: */
|
2005-12-21 03:14:06 +00:00
|
|
|
extern pthreadlist _thread_gc_list __hidden;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2005-12-21 03:14:06 +00:00
|
|
|
extern int _thread_active_threads;
|
|
|
|
extern atfork_head _thr_atfork_list __hidden;
|
2010-09-01 03:11:21 +00:00
|
|
|
extern struct urwlock _thr_atfork_lock __hidden;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
/* Default thread attributes: */
|
2005-12-21 03:14:06 +00:00
|
|
|
extern struct pthread_attr _pthread_attr_default __hidden;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
/* Default mutex attributes: */
|
2005-12-21 03:14:06 +00:00
|
|
|
extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
|
2010-09-28 04:57:56 +00:00
|
|
|
extern struct pthread_mutex_attr _pthread_mutexattr_adaptive_default __hidden;
|
2004-07-18 04:23:30 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Default condition variable attributes: */
|
2005-12-21 03:14:06 +00:00
|
|
|
extern struct pthread_cond_attr _pthread_condattr_default __hidden;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2006-04-27 08:18:23 +00:00
|
|
|
extern struct pthread_prio _thr_priorities[] __hidden;
|
|
|
|
|
2006-12-15 11:52:01 +00:00
|
|
|
extern int _thr_is_smp __hidden;
|
2006-08-08 04:42:41 +00:00
|
|
|
|
2006-04-04 02:57:49 +00:00
|
|
|
extern size_t _thr_guard_default __hidden;
|
|
|
|
extern size_t _thr_stack_default __hidden;
|
|
|
|
extern size_t _thr_stack_initial __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
extern int _thr_page_size __hidden;
|
Add my recent work of adaptive spin mutex code. Use two environments variable
to tune pthread mutex performance:
1. LIBPTHREAD_SPINLOOPS
If a pthread mutex is being locked by another thread, this environment
variable sets total number of spin loops before the current thread
sleeps in kernel, this saves a syscall overhead if the mutex will be
unlocked very soon (well written application code).
2. LIBPTHREAD_YIELDLOOPS
If a pthread mutex is being locked by other threads, this environment
variable sets total number of sched_yield() loops before the currrent
thread sleeps in kernel. if a pthread mutex is locked, the current thread
gives up cpu, but will not sleep in kernel, this means, current thread
does not set contention bit in mutex, but let lock owner to run again
if the owner is on kernel's run queue, and when lock owner unlocks the
mutex, it does not need to enter kernel and do lots of work to resume
mutex waiters, in some cases, this saves lots of syscall overheads for
mutex owner.
In my practice, sometimes LIBPTHREAD_YIELDLOOPS can massively improve performance
than LIBPTHREAD_SPINLOOPS, this depends on application. These two environments
are global to all pthread mutex, there is no interface to set them for each
pthread mutex, the default values are zero, this means spinning is turned off
by default.
2007-10-30 05:57:37 +00:00
|
|
|
extern int _thr_spinloops __hidden;
|
|
|
|
extern int _thr_yieldloops __hidden;
|
2012-05-03 09:17:31 +00:00
|
|
|
extern int _thr_queuefifo __hidden;
|
Add my recent work of adaptive spin mutex code. Use two environments variable
to tune pthread mutex performance:
1. LIBPTHREAD_SPINLOOPS
If a pthread mutex is being locked by another thread, this environment
variable sets total number of spin loops before the current thread
sleeps in kernel, this saves a syscall overhead if the mutex will be
unlocked very soon (well written application code).
2. LIBPTHREAD_YIELDLOOPS
If a pthread mutex is being locked by other threads, this environment
variable sets total number of sched_yield() loops before the currrent
thread sleeps in kernel. if a pthread mutex is locked, the current thread
gives up cpu, but will not sleep in kernel, this means, current thread
does not set contention bit in mutex, but let lock owner to run again
if the owner is on kernel's run queue, and when lock owner unlocks the
mutex, it does not need to enter kernel and do lots of work to resume
mutex waiters, in some cases, this saves lots of syscall overheads for
mutex owner.
In my practice, sometimes LIBPTHREAD_YIELDLOOPS can massively improve performance
than LIBPTHREAD_SPINLOOPS, this depends on application. These two environments
are global to all pthread mutex, there is no interface to set them for each
pthread mutex, the default values are zero, this means spinning is turned off
by default.
2007-10-30 05:57:37 +00:00
|
|
|
|
2005-12-21 03:14:06 +00:00
|
|
|
/* Garbage thread count. */
|
|
|
|
extern int _gc_count __hidden;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2006-09-06 04:04:10 +00:00
|
|
|
extern struct umutex _mutex_static_lock __hidden;
|
|
|
|
extern struct umutex _cond_static_lock __hidden;
|
|
|
|
extern struct umutex _rwlock_static_lock __hidden;
|
|
|
|
extern struct umutex _keytable_lock __hidden;
|
2010-09-13 07:03:01 +00:00
|
|
|
extern struct urwlock _thr_list_lock __hidden;
|
2006-09-06 04:04:10 +00:00
|
|
|
extern struct umutex _thr_event_lock __hidden;
|
2012-08-27 03:09:39 +00:00
|
|
|
extern struct umutex _suspend_all_lock __hidden;
|
|
|
|
extern int _suspend_all_waiters __hidden;
|
|
|
|
extern int _suspend_all_cycle __hidden;
|
|
|
|
extern struct pthread *_single_thread __hidden;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function prototype definitions.
|
|
|
|
*/
|
|
|
|
__BEGIN_DECLS
|
2018-11-30 03:01:32 +00:00
|
|
|
void _thr_setthreaded(int) __hidden;
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
int _mutex_cv_lock(struct pthread_mutex *, int, bool) __hidden;
|
2012-08-11 23:17:02 +00:00
|
|
|
int _mutex_cv_unlock(struct pthread_mutex *, int *, int *) __hidden;
|
|
|
|
int _mutex_cv_attach(struct pthread_mutex *, int) __hidden;
|
|
|
|
int _mutex_cv_detach(struct pthread_mutex *, int *) __hidden;
|
2010-12-22 05:01:52 +00:00
|
|
|
int _mutex_owned(struct pthread *, const struct pthread_mutex *) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
int _mutex_reinit(pthread_mutex_t *) __hidden;
|
|
|
|
void _mutex_fork(struct pthread *curthread) __hidden;
|
Add implementation of robust mutexes, hopefully close enough to the
intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013.
A robust mutex is guaranteed to be cleared by the system upon either
thread or process owner termination while the mutex is held. The next
mutex locker is then notified about inconsistent mutex state and can
execute (or abandon) corrective actions.
The patch mostly consists of small changes here and there, adding
neccessary checks for the inconsistent and abandoned conditions into
existing paths. Additionally, the thread exit handler was extended to
iterate over the userspace-maintained list of owned robust mutexes,
unlocking and marking as terminated each of them.
The list of owned robust mutexes cannot be maintained atomically
synchronous with the mutex lock state (it is possible in kernel, but
is too expensive). Instead, for the duration of lock or unlock
operation, the current mutex is remembered in a special slot that is
also checked by the kernel at thread termination.
Kernel must be aware about the per-thread location of the heads of
robust mutex lists and the current active mutex slot. When a thread
touches a robust mutex for the first time, a new umtx op syscall is
issued which informs about location of lists heads.
The umtx sleep queues for PP and PI mutexes are split between
non-robust and robust.
Somewhat unrelated changes in the patch:
1. Style.
2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared
pi mutexes.
3. Removal of the userspace struct pthread_mutex m_owner field.
4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls
the lifetime of the shared mutex associated with a vnode' page.
Reviewed by: jilles (previous version, supposedly the objection was fixed)
Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects)
Tested by: pho
Sponsored by: The FreeBSD Foundation
2016-05-17 09:56:22 +00:00
|
|
|
int _mutex_enter_robust(struct pthread *curthread, struct pthread_mutex *m)
|
|
|
|
__hidden;
|
|
|
|
void _mutex_leave_robust(struct pthread *curthread, struct pthread_mutex *m)
|
|
|
|
__hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
void _libpthread_init(struct pthread *) __hidden;
|
|
|
|
struct pthread *_thr_alloc(struct pthread *) __hidden;
|
2006-04-04 02:57:49 +00:00
|
|
|
void _thread_exit(const char *, int, const char *) __hidden __dead2;
|
2016-06-01 16:09:56 +00:00
|
|
|
void _thread_exitf(const char *, int, const char *, ...) __hidden __dead2
|
|
|
|
__printflike(3, 4);
|
2005-12-21 03:14:06 +00:00
|
|
|
int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
|
|
|
|
void _thr_ref_delete(struct pthread *, struct pthread *) __hidden;
|
2006-01-05 13:51:22 +00:00
|
|
|
void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden;
|
|
|
|
void _thr_rtld_init(void) __hidden;
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
void _thr_rtld_postfork_child(void) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
int _thr_stack_alloc(struct pthread_attr *) __hidden;
|
|
|
|
void _thr_stack_free(struct pthread_attr *) __hidden;
|
|
|
|
void _thr_free(struct pthread *, struct pthread *) __hidden;
|
|
|
|
void _thr_gc(struct pthread *) __hidden;
|
|
|
|
void _thread_cleanupspecific(void) __hidden;
|
2016-06-01 16:09:56 +00:00
|
|
|
void _thread_printf(int, const char *, ...) __hidden __printflike(2, 3);
|
|
|
|
void _thread_vprintf(int, const char *, va_list) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
void _thr_spinlock_init(void) __hidden;
|
2006-11-24 09:57:38 +00:00
|
|
|
void _thr_cancel_enter(struct pthread *) __hidden;
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
void _thr_cancel_enter2(struct pthread *, int) __hidden;
|
|
|
|
void _thr_cancel_leave(struct pthread *, int) __hidden;
|
2006-11-24 09:57:38 +00:00
|
|
|
void _thr_testcancel(struct pthread *) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
void _thr_signal_block(struct pthread *) __hidden;
|
|
|
|
void _thr_signal_unblock(struct pthread *) __hidden;
|
2020-02-09 12:27:22 +00:00
|
|
|
void _thr_signal_block_check_fast(void) __hidden;
|
|
|
|
void _thr_signal_block_setup(struct pthread *) __hidden;
|
2015-01-03 18:38:46 +00:00
|
|
|
void _thr_signal_init(int) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
void _thr_signal_deinit(void) __hidden;
|
|
|
|
int _thr_send_sig(struct pthread *, int sig) __hidden;
|
|
|
|
void _thr_list_init(void) __hidden;
|
|
|
|
void _thr_hash_add(struct pthread *) __hidden;
|
|
|
|
void _thr_hash_remove(struct pthread *) __hidden;
|
|
|
|
struct pthread *_thr_hash_find(struct pthread *) __hidden;
|
2006-01-05 13:51:22 +00:00
|
|
|
void _thr_link(struct pthread *, struct pthread *) __hidden;
|
|
|
|
void _thr_unlink(struct pthread *, struct pthread *) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
void _thr_assert_lock_level(void) __hidden __dead2;
|
2006-01-05 13:51:22 +00:00
|
|
|
void _thr_ast(struct pthread *) __hidden;
|
2005-04-12 03:00:28 +00:00
|
|
|
void _thr_report_creation(struct pthread *curthread,
|
2006-04-04 02:57:49 +00:00
|
|
|
struct pthread *newthread) __hidden;
|
2005-12-21 03:14:06 +00:00
|
|
|
void _thr_report_death(struct pthread *curthread) __hidden;
|
2006-09-21 04:21:30 +00:00
|
|
|
int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden;
|
|
|
|
int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden;
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
void _thr_signal_prefork(void) __hidden;
|
|
|
|
void _thr_signal_postfork(void) __hidden;
|
|
|
|
void _thr_signal_postfork_child(void) __hidden;
|
2012-08-27 03:09:39 +00:00
|
|
|
void _thr_suspend_all_lock(struct pthread *) __hidden;
|
|
|
|
void _thr_suspend_all_unlock(struct pthread *) __hidden;
|
2010-09-13 07:03:01 +00:00
|
|
|
void _thr_try_gc(struct pthread *, struct pthread *) __hidden;
|
2006-09-21 04:21:30 +00:00
|
|
|
int _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
|
|
|
|
struct sched_param *param) __hidden;
|
|
|
|
int _schedparam_to_rtp(int policy, const struct sched_param *param,
|
|
|
|
struct rtprio *rtp) __hidden;
|
2005-04-12 03:00:28 +00:00
|
|
|
void _thread_bp_create(void);
|
|
|
|
void _thread_bp_death(void);
|
Add my recent work of adaptive spin mutex code. Use two environments variable
to tune pthread mutex performance:
1. LIBPTHREAD_SPINLOOPS
If a pthread mutex is being locked by another thread, this environment
variable sets total number of spin loops before the current thread
sleeps in kernel, this saves a syscall overhead if the mutex will be
unlocked very soon (well written application code).
2. LIBPTHREAD_YIELDLOOPS
If a pthread mutex is being locked by other threads, this environment
variable sets total number of sched_yield() loops before the currrent
thread sleeps in kernel. if a pthread mutex is locked, the current thread
gives up cpu, but will not sleep in kernel, this means, current thread
does not set contention bit in mutex, but let lock owner to run again
if the owner is on kernel's run queue, and when lock owner unlocks the
mutex, it does not need to enter kernel and do lots of work to resume
mutex waiters, in some cases, this saves lots of syscall overheads for
mutex owner.
In my practice, sometimes LIBPTHREAD_YIELDLOOPS can massively improve performance
than LIBPTHREAD_SPINLOOPS, this depends on application. These two environments
are global to all pthread mutex, there is no interface to set them for each
pthread mutex, the default values are zero, this means spinning is turned off
by default.
2007-10-30 05:57:37 +00:00
|
|
|
int _sched_yield(void);
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2008-06-09 01:14:10 +00:00
|
|
|
void _pthread_cleanup_push(void (*)(void *), void *);
|
|
|
|
void _pthread_cleanup_pop(int);
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden;
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
2010-09-25 01:57:47 +00:00
|
|
|
void _pthread_cancel_enter(int maycancel);
|
|
|
|
void _pthread_cancel_leave(int maycancel);
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif
|
2017-01-28 20:54:43 +00:00
|
|
|
int _pthread_mutex_consistent(pthread_mutex_t * _Nonnull);
|
|
|
|
int _pthread_mutexattr_getrobust(pthread_mutexattr_t * _Nonnull __restrict,
|
|
|
|
int * _Nonnull __restrict);
|
|
|
|
int _pthread_mutexattr_setrobust(pthread_mutexattr_t * _Nonnull, int);
|
2008-06-09 01:14:10 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* #include <fcntl.h> */
|
|
|
|
#ifdef _SYS_FCNTL_H_
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
2005-04-02 01:20:00 +00:00
|
|
|
int __sys_fcntl(int, int, ...);
|
2009-10-11 20:19:45 +00:00
|
|
|
int __sys_openat(int, const char *, int, ...);
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif /* _LIBC_PRIVATE_H_ */
|
|
|
|
#endif /* _SYS_FCNTL_H_ */
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* #include <signal.h> */
|
|
|
|
#ifdef _SIGNAL_H_
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
|
|
|
int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
|
2005-04-02 01:20:00 +00:00
|
|
|
int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
|
|
|
|
int __sys_sigsuspend(const sigset_t *);
|
2006-04-04 02:57:49 +00:00
|
|
|
int __sys_sigtimedwait(const sigset_t *, siginfo_t *,
|
|
|
|
const struct timespec *);
|
2017-05-23 16:12:50 +00:00
|
|
|
int __sys_sigwait(const sigset_t *, int *);
|
2006-04-04 02:57:49 +00:00
|
|
|
int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif /* _LIBC_PRIVATE_H_ */
|
|
|
|
#endif /* _SYS_FCNTL_H_ */
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* #include <time.h> */
|
|
|
|
#ifdef _TIME_H_
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
2017-03-19 00:51:12 +00:00
|
|
|
int __sys_clock_nanosleep(clockid_t, int, const struct timespec *,
|
|
|
|
struct timespec *);
|
2005-04-02 01:20:00 +00:00
|
|
|
int __sys_nanosleep(const struct timespec *, struct timespec *);
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif /* _LIBC_PRIVATE_H_ */
|
|
|
|
#endif /* _SYS_FCNTL_H_ */
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2010-08-24 09:57:06 +00:00
|
|
|
/* #include <sys/ucontext.h> */
|
|
|
|
#ifdef _SYS_UCONTEXT_H_
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
2010-08-24 09:57:06 +00:00
|
|
|
int __sys_setcontext(const ucontext_t *ucp);
|
|
|
|
int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif /* _LIBC_PRIVATE_H_ */
|
|
|
|
#endif /* _SYS_FCNTL_H_ */
|
2010-08-24 09:57:06 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* #include <unistd.h> */
|
|
|
|
#ifdef _UNISTD_H_
|
2017-05-23 16:12:50 +00:00
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
2005-04-02 01:20:00 +00:00
|
|
|
int __sys_close(int);
|
|
|
|
int __sys_fork(void);
|
|
|
|
ssize_t __sys_read(int, void *, size_t);
|
2017-05-23 16:12:50 +00:00
|
|
|
#endif /* _LIBC_PRIVATE_H_ */
|
|
|
|
#endif /* _SYS_FCNTL_H_ */
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
static inline int
|
|
|
|
_thr_isthreaded(void)
|
|
|
|
{
|
|
|
|
return (__isthreaded != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
_thr_is_inited(void)
|
|
|
|
{
|
|
|
|
return (_thr_initial != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_thr_check_init(void)
|
|
|
|
{
|
|
|
|
if (_thr_initial == NULL)
|
|
|
|
_libpthread_init(NULL);
|
|
|
|
}
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2010-12-22 05:01:52 +00:00
|
|
|
struct wake_addr *_thr_alloc_wake_addr(void);
|
|
|
|
void _thr_release_wake_addr(struct wake_addr *);
|
|
|
|
int _thr_sleep(struct pthread *, int, const struct timespec *);
|
|
|
|
|
|
|
|
void _thr_wake_addr_init(void) __hidden;
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_thr_clear_wake(struct pthread *td)
|
|
|
|
{
|
|
|
|
td->wake_addr->value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
_thr_is_woken(struct pthread *td)
|
|
|
|
{
|
|
|
|
return td->wake_addr->value != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_thr_set_wake(unsigned int *waddr)
|
|
|
|
{
|
|
|
|
*waddr = 1;
|
|
|
|
_thr_umtx_wake(waddr, INT_MAX, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _thr_wake_all(unsigned int *waddrs[], int) __hidden;
|
|
|
|
|
|
|
|
static inline struct pthread *
|
|
|
|
_sleepq_first(struct sleepqueue *sq)
|
|
|
|
{
|
|
|
|
return TAILQ_FIRST(&sq->sq_blocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _sleepq_init(void) __hidden;
|
|
|
|
struct sleepqueue *_sleepq_alloc(void) __hidden;
|
|
|
|
void _sleepq_free(struct sleepqueue *) __hidden;
|
|
|
|
void _sleepq_lock(void *) __hidden;
|
|
|
|
void _sleepq_unlock(void *) __hidden;
|
|
|
|
struct sleepqueue *_sleepq_lookup(void *) __hidden;
|
|
|
|
void _sleepq_add(void *, struct pthread *) __hidden;
|
|
|
|
int _sleepq_remove(struct sleepqueue *, struct pthread *) __hidden;
|
|
|
|
void _sleepq_drop(struct sleepqueue *,
|
|
|
|
void (*cb)(struct pthread *, void *arg), void *) __hidden;
|
|
|
|
|
2015-01-03 18:38:46 +00:00
|
|
|
int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
|
|
|
|
void *(calloc_cb)(size_t, size_t));
|
|
|
|
|
2010-08-23 15:38:02 +00:00
|
|
|
struct dl_phdr_info;
|
|
|
|
void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info);
|
2010-08-27 05:20:22 +00:00
|
|
|
void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden;
|
Add signal handler wrapper, the reason to add it becauses there are
some cases we want to improve:
1) if a thread signal got a signal while in cancellation point,
it is possible the TDP_WAKEUP may be eaten by signal handler
if the handler called some interruptibly system calls.
2) In signal handler, we want to disable cancellation.
3) When thread holding some low level locks, it is better to
disable signal, those code need not to worry reentrancy,
sigprocmask system call is avoided because it is a bit expensive.
The signal handler wrapper works in this way:
1) libthr installs its signal handler if user code invokes sigaction
to install its handler, the user handler is recorded in internal
array.
2) when a signal is delivered, libthr's signal handler is invoke,
libthr checks if thread holds some low level lock or is in critical
region, if it is true, the signal is buffered, and all signals are
masked, once the thread leaves critical region, correct signal
mask is restored and buffered signal is processed.
3) before user signal handler is invoked, cancellation is temporarily
disabled, after user signal handler is returned, cancellation state
is restored, and pending cancellation is rescheduled.
2010-09-01 02:18:33 +00:00
|
|
|
void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden;
|
2011-01-09 12:38:40 +00:00
|
|
|
void _thr_stack_fix_protection(struct pthread *thrd);
|
2019-03-29 17:52:57 +00:00
|
|
|
void __pthread_distribute_static_tls(size_t offset, void *src, size_t len,
|
|
|
|
size_t total_len);
|
2010-08-23 15:38:02 +00:00
|
|
|
|
2015-01-05 01:06:54 +00:00
|
|
|
int *__error_threaded(void) __hidden;
|
2015-01-03 18:38:46 +00:00
|
|
|
void __thr_interpose_libc(void) __hidden;
|
|
|
|
pid_t __thr_fork(void);
|
2021-01-10 19:22:49 +00:00
|
|
|
pid_t __thr_pdfork(int *, int);
|
2015-01-03 18:38:46 +00:00
|
|
|
int __thr_setcontext(const ucontext_t *ucp);
|
|
|
|
int __thr_sigaction(int sig, const struct sigaction *act,
|
|
|
|
struct sigaction *oact) __hidden;
|
|
|
|
int __thr_sigprocmask(int how, const sigset_t *set, sigset_t *oset);
|
|
|
|
int __thr_sigsuspend(const sigset_t * set);
|
|
|
|
int __thr_sigtimedwait(const sigset_t *set, siginfo_t *info,
|
|
|
|
const struct timespec * timeout);
|
|
|
|
int __thr_sigwait(const sigset_t *set, int *sig);
|
|
|
|
int __thr_sigwaitinfo(const sigset_t *set, siginfo_t *info);
|
|
|
|
int __thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
|
|
|
|
|
2016-02-08 19:24:13 +00:00
|
|
|
void __thr_map_stacks_exec(void);
|
|
|
|
|
2015-02-14 11:47:40 +00:00
|
|
|
struct _spinlock;
|
|
|
|
void __thr_spinunlock(struct _spinlock *lck);
|
|
|
|
void __thr_spinlock(struct _spinlock *lck);
|
|
|
|
|
2015-01-21 16:41:05 +00:00
|
|
|
struct tcb *_tcb_ctor(struct pthread *, int);
|
|
|
|
void _tcb_dtor(struct tcb *);
|
|
|
|
|
2016-02-28 17:52:33 +00:00
|
|
|
void __thr_pshared_init(void) __hidden;
|
|
|
|
void *__thr_pshared_offpage(void *key, int doalloc) __hidden;
|
|
|
|
void __thr_pshared_destroy(void *key) __hidden;
|
2016-03-21 06:52:35 +00:00
|
|
|
void __thr_pshared_atfork_pre(void) __hidden;
|
|
|
|
void __thr_pshared_atfork_post(void) __hidden;
|
2016-02-28 17:52:33 +00:00
|
|
|
|
2019-01-29 22:46:44 +00:00
|
|
|
void *__thr_calloc(size_t num, size_t size);
|
|
|
|
void __thr_free(void *cp);
|
|
|
|
void *__thr_malloc(size_t nbytes);
|
|
|
|
void *__thr_realloc(void *cp, size_t nbytes);
|
|
|
|
void __thr_malloc_init(void);
|
|
|
|
void __thr_malloc_prefork(struct pthread *curthread);
|
|
|
|
void __thr_malloc_postfork(struct pthread *curthread);
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
int _thr_join(pthread_t, void **);
|
|
|
|
int _Tthr_kill(pthread_t, int);
|
|
|
|
int _thr_getthreadid_np(void);
|
|
|
|
void __thr_cleanup_push_imp(void (*)(void *), void *,
|
|
|
|
struct _pthread_cleanup_info *);
|
|
|
|
void __thr_cleanup_pop_imp(int);
|
|
|
|
void _thr_cleanup_push(void (*)(void *), void *);
|
|
|
|
void _thr_cleanup_pop(int);
|
|
|
|
void _Tthr_testcancel(void);
|
2019-08-21 19:53:50 +00:00
|
|
|
void _Tthr_cancel_enter(int);
|
|
|
|
void _Tthr_cancel_leave(int);
|
2019-07-31 19:27:20 +00:00
|
|
|
int _thr_cancel(pthread_t);
|
|
|
|
int _thr_atfork(void (*)(void), void (*)(void), void (*)(void));
|
|
|
|
int _thr_attr_destroy(pthread_attr_t *);
|
|
|
|
int _thr_attr_get_np(pthread_t, pthread_attr_t *);
|
|
|
|
int _thr_attr_getdetachstate(const pthread_attr_t *, int *);
|
|
|
|
int _thr_attr_getguardsize(const pthread_attr_t * __restrict,
|
|
|
|
size_t * __restrict);
|
|
|
|
int _thr_attr_getinheritsched(const pthread_attr_t * __restrict,
|
|
|
|
int * __restrict);
|
|
|
|
int _thr_attr_getschedparam(const pthread_attr_t * __restrict,
|
|
|
|
struct sched_param * __restrict);
|
|
|
|
int _thr_attr_getschedpolicy(const pthread_attr_t * __restrict,
|
|
|
|
int * __restrict);
|
|
|
|
int _thr_attr_getscope(const pthread_attr_t * __restrict, int * __restrict);
|
|
|
|
int _thr_attr_getstackaddr(const pthread_attr_t *, void **);
|
|
|
|
int _thr_attr_getstacksize(const pthread_attr_t * __restrict,
|
|
|
|
size_t * __restrict);
|
|
|
|
int _thr_attr_init(pthread_attr_t *);
|
|
|
|
int _thr_attr_setdetachstate(pthread_attr_t *, int);
|
|
|
|
int _thr_attr_setguardsize(pthread_attr_t *, size_t);
|
|
|
|
int _thr_attr_setinheritsched(pthread_attr_t *, int);
|
|
|
|
int _thr_attr_setschedparam(pthread_attr_t * __restrict,
|
|
|
|
const struct sched_param * __restrict);
|
|
|
|
int _thr_attr_setschedpolicy(pthread_attr_t *, int);
|
|
|
|
int _thr_attr_setscope(pthread_attr_t *, int);
|
|
|
|
int _thr_attr_setstackaddr(pthread_attr_t *, void *);
|
|
|
|
int _thr_attr_setstacksize(pthread_attr_t *, size_t);
|
|
|
|
int _thr_cond_init(pthread_cond_t * __restrict,
|
|
|
|
const pthread_condattr_t * __restrict);
|
|
|
|
int _thr_cond_destroy(pthread_cond_t *);
|
|
|
|
int _thr_cond_timedwait(pthread_cond_t * __restrict,
|
|
|
|
pthread_mutex_t * __restrict, const struct timespec * __restrict);
|
|
|
|
int _thr_cond_signal(pthread_cond_t * cond);
|
|
|
|
int _thr_cond_broadcast(pthread_cond_t * cond);
|
|
|
|
int __thr_cond_wait(pthread_cond_t *, pthread_mutex_t *);
|
|
|
|
int _thr_cond_wait(pthread_cond_t *, pthread_mutex_t *);
|
|
|
|
int _thr_detach(pthread_t);
|
|
|
|
int _thr_equal(pthread_t, pthread_t);
|
|
|
|
void _Tthr_exit(void *);
|
|
|
|
int _thr_key_create(pthread_key_t *, void (*)(void *));
|
|
|
|
int _thr_key_delete(pthread_key_t);
|
|
|
|
int _thr_setspecific(pthread_key_t, const void *);
|
|
|
|
void *_thr_getspecific(pthread_key_t);
|
|
|
|
int _thr_setcancelstate(int, int *);
|
|
|
|
int _thr_setcanceltype(int, int *);
|
|
|
|
pthread_t _Tthr_self(void);
|
|
|
|
int _thr_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *);
|
|
|
|
int _thr_rwlock_destroy(pthread_rwlock_t *);
|
|
|
|
int _Tthr_rwlock_rdlock(pthread_rwlock_t *);
|
|
|
|
int _Tthr_rwlock_tryrdlock(pthread_rwlock_t *);
|
|
|
|
int _Tthr_rwlock_trywrlock(pthread_rwlock_t *);
|
|
|
|
int _Tthr_rwlock_wrlock(pthread_rwlock_t *);
|
|
|
|
int _Tthr_rwlock_unlock(pthread_rwlock_t *);
|
|
|
|
int _thr_once(pthread_once_t *, void (*)(void));
|
|
|
|
int _thr_sigmask(int, const sigset_t *, sigset_t *);
|
|
|
|
int _thr_main_np(void);
|
|
|
|
int _thr_mutexattr_init(pthread_mutexattr_t *);
|
|
|
|
int _thr_mutexattr_destroy(pthread_mutexattr_t *);
|
|
|
|
int _thr_mutexattr_settype(pthread_mutexattr_t *, int);
|
|
|
|
int _thr_mutexattr_getrobust(pthread_mutexattr_t *, int *);
|
|
|
|
int _thr_mutexattr_setrobust(pthread_mutexattr_t *, int);
|
|
|
|
int __Tthr_mutex_init(pthread_mutex_t * __restrict,
|
|
|
|
const pthread_mutexattr_t * __restrict);
|
|
|
|
int _Tthr_mutex_consistent(pthread_mutex_t *);
|
|
|
|
int _thr_mutex_destroy(pthread_mutex_t *);
|
|
|
|
int _thr_mutex_unlock(pthread_mutex_t *);
|
|
|
|
int __Tthr_mutex_lock(pthread_mutex_t *);
|
|
|
|
int __Tthr_mutex_trylock(pthread_mutex_t *);
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
__END_DECLS
|
2017-01-28 20:54:43 +00:00
|
|
|
__NULLABILITY_PRAGMA_POP
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
#endif /* !_THR_PRIVATE_H */
|