2 * Copyright (c) 2019 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __LIBPTHREAD_PROTOTYPES_INTERNAL_H__
25 #define __LIBPTHREAD_PROTOTYPES_INTERNAL_H__
28 * @file prototypes_internal.h
31 * This file has prototypes for symbols / functions private to libpthread.
34 #define PTHREAD_NOEXPORT __attribute__((visibility("hidden")))
35 #define PTHREAD_NOEXPORT_VARIANT
38 #pragma GCC visibility push(hidden)
41 * @macro main_thread()
44 * Returns a pointer to the main thread.
47 * The main thread structure really lives in dyld,
48 * and when __pthread_init() is called, its pointer will be discovered
49 * and stashed in _main_thread_ptr which libpthread uses.
52 extern struct pthread_s _main_thread
;
53 #define main_thread() (&_main_thread)
54 #define __pthread_mutex_default_opt_policy _PTHREAD_MTX_OPT_POLICY_DEFAULT
55 #define __pthread_mutex_use_ulock _PTHREAD_MTX_OPT_ULOCK_DEFAULT
56 #define __pthread_mutex_ulock_adaptive_spin _PTHREAD_MTX_OPT_ADAPTIVE_DEFAULT
58 extern pthread_t _main_thread_ptr
;
59 #define main_thread() (_main_thread_ptr)
60 extern void *(*_pthread_malloc
)(size_t);
61 extern void (*_pthread_free
)(void *);
62 extern int __pthread_mutex_default_opt_policy
;
63 extern bool __pthread_mutex_use_ulock
;
64 extern bool __pthread_mutex_ulock_adaptive_spin
;
65 #endif // VARIANT_DYLD
67 extern struct __pthread_list __pthread_head
; // List of all pthreads in the process.
68 extern _pthread_lock _pthread_list_lock
; // Lock protects access to above list.
69 extern uint32_t _main_qos
;
70 extern uintptr_t _pthread_ptr_munge_token
;
73 #include <mach/mach_time.h>
74 extern int _pthread_debuglog
;
75 extern uint64_t _pthread_debugstart
;
79 void _pthread_deallocate(pthread_t t
, bool from_mach_thread
);
80 void _pthread_main_thread_init(pthread_t p
, mach_port_name_t main_th
);
81 void _pthread_main_thread_postfork_init(pthread_t p
);
82 void _pthread_bsdthread_init(struct _pthread_registration_data
*data
);
83 void *_pthread_atomic_xchg_ptr(void **p
, void *v
);
84 uint32_t _pthread_atomic_xchg_uint32_relaxed(uint32_t *p
, uint32_t v
);
86 /* pthread_cancelable.c */
87 void _pthread_markcancel_if_canceled(pthread_t thread
, mach_port_t kport
);
88 void _pthread_setcancelstate_exit(pthread_t self
, void *value_ptr
);
89 semaphore_t
_pthread_joiner_prepost_wake(pthread_t thread
);
90 int _pthread_join(pthread_t thread
, void **value_ptr
, pthread_conformance_t
);
93 int _pthread_cond_wait(pthread_cond_t
*cond
, pthread_mutex_t
*mutex
,
94 const struct timespec
*abstime
, int isRelative
, pthread_conformance_t
);
95 int _pthread_mutex_droplock(pthread_mutex_t
*mutex
, uint32_t *flagp
,
96 uint32_t **pmtxp
, uint32_t *mgenp
, uint32_t *ugenp
);
98 /* pthread_dependency.c */
99 void _pthread_dependency_fulfill_slow(pthread_dependency_t
*pr
, uint32_t old
);
101 /* pthread_mutex.c */
103 int _pthread_mutex_corruption_abort(pthread_mutex_t
*mutex
);
104 int _pthread_mutex_fairshare_lock_slow(pthread_mutex_t
*mutex
, bool trylock
);
105 int _pthread_mutex_fairshare_unlock_slow(pthread_mutex_t
*mutex
);
106 int _pthread_mutex_ulock_lock(pthread_mutex_t
*mutex
, bool trylock
);
107 int _pthread_mutex_ulock_unlock(pthread_mutex_t
*mutex
);
108 int _pthread_mutex_firstfit_lock_slow(pthread_mutex_t
*mutex
, bool trylock
);
109 int _pthread_mutex_firstfit_unlock_slow(pthread_mutex_t
*mutex
);
110 int _pthread_mutex_lock_init_slow(pthread_mutex_t
*mutex
, bool trylock
);
111 void _pthread_mutex_global_init(const char *envp
[], struct _pthread_registration_data
*registration_data
);
113 /* pthread_rwlock.c */
114 enum rwlock_seqfields
;
115 int _pthread_rwlock_lock_slow(pthread_rwlock_t
*rwlock
, bool readlock
, bool trylock
);
116 int _pthread_rwlock_unlock_slow(pthread_rwlock_t
*rwlock
, enum rwlock_seqfields updated_seqfields
);
119 void _pthread_tsd_cleanup(pthread_t self
);
120 void _pthread_key_global_init(const char *envp
[]);
123 thread_qos_t
_pthread_qos_class_to_thread_qos(qos_class_t qos
);
124 void _pthread_set_main_qos(pthread_priority_t qos
);
126 #pragma GCC visibility pop
128 #endif // __LIBPTHREAD_PROTOTYPES_INTERNAL_H__