]> git.saurik.com Git - apple/libpthread.git/blob - src/prototypes_internal.h
libpthread-454.100.8.tar.gz
[apple/libpthread.git] / src / prototypes_internal.h
1 /*
2 * Copyright (c) 2019 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef __LIBPTHREAD_PROTOTYPES_INTERNAL_H__
25 #define __LIBPTHREAD_PROTOTYPES_INTERNAL_H__
26
27 /*!
28 * @file prototypes_internal.h
29 *
30 * @brief
31 * This file has prototypes for symbols / functions private to libpthread.
32 */
33
34 #define PTHREAD_NOEXPORT __attribute__((visibility("hidden")))
35 #define PTHREAD_NOEXPORT_VARIANT
36
37
38 #pragma GCC visibility push(hidden)
39
40 /*!
41 * @macro main_thread()
42 *
43 * @brief
44 * Returns a pointer to the main thread.
45 *
46 * @discussion
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.
50 */
51 #if VARIANT_DYLD
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
57 #else // VARIANT_DYLD
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
66
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;
71
72 #if PTHREAD_DEBUG_LOG
73 #include <mach/mach_time.h>
74 extern int _pthread_debuglog;
75 extern uint64_t _pthread_debugstart;
76 #endif
77
78 /* pthread.c */
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);
85
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);
91
92 /* pthread_cond.c */
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);
97
98 /* pthread_dependency.c */
99 void _pthread_dependency_fulfill_slow(pthread_dependency_t *pr, uint32_t old);
100
101 /* pthread_mutex.c */
102 OS_COLD OS_NORETURN
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);
112
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);
117
118 /* pthread_tsd.c */
119 void _pthread_tsd_cleanup(pthread_t self);
120 void _pthread_key_global_init(const char *envp[]);
121
122 /* qos.c */
123 thread_qos_t _pthread_qos_class_to_thread_qos(qos_class_t qos);
124 void _pthread_set_main_qos(pthread_priority_t qos);
125
126 #pragma GCC visibility pop
127
128 #endif // __LIBPTHREAD_PROTOTYPES_INTERNAL_H__