Merge "Document pthread_key_create(3), pthread_key_delete(3), and PTHREAD_KEYS_MAX." into main am: ed21ffc70a am: 7f1b24cbbf

Original change: https://android-review.googlesource.com/c/platform/bionic/+/3046887

Change-Id: Ifaf03a30ed6ffe00da577cfa1fea23e0e4ddc87f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Elliott Hughes 2024-04-20 16:00:56 +00:00 committed by Automerger Merge Worker
commit 28366054e3
2 changed files with 30 additions and 2 deletions

View file

@ -148,9 +148,15 @@
/* >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS */
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
/* >= _POSIX_THREAD_KEYS_MAX */
/**
* The number of calls to pthread_key_create() without intervening calls to
* pthread_key_delete() that are guaranteed to succeed. See pthread_key_create()
* for more details and ways to avoid hitting this limit.
*/
#define PTHREAD_KEYS_MAX 128
/* bionic has no specific limit */
/** bionic has no specific limit on the number of threads. */
#undef PTHREAD_THREADS_MAX
#endif /* !_LIMITS_H_ */

View file

@ -174,7 +174,29 @@ pid_t pthread_gettid_np(pthread_t __pthread);
int pthread_join(pthread_t __pthread, void* _Nullable * _Nullable __return_value_ptr);
/**
* [pthread_key_create(3)](https://man7.org/linux/man-pages/man3/pthread_key_create.3p.html)
* creates a key for thread-specific data.
*
* There is a limit of `PTHREAD_KEYS_MAX` keys per process, but most callers
* should just use the C or C++ `thread_local` storage specifier anyway. When
* targeting new enough OS versions, the compiler will automatically use
* ELF TLS; when targeting old OS versions the emutls implementation will
* multiplex pthread keys behind the scenes, using one per library rather than
* one per thread-local variable. If you are implementing the runtime for a
* different language, you should consider similar implementation choices and
* avoid a direct one-to-one mapping from thread locals to pthread keys.
*
* Returns 0 on success and returns an error number on failure.
*/
int pthread_key_create(pthread_key_t* _Nonnull __key_ptr, void (* _Nullable __key_destructor)(void* _Nullable));
/**
* [pthread_key_delete(3)](https://man7.org/linux/man-pages/man3/pthread_key_delete.3p.html)
* deletes a key for thread-specific data.
*
* Returns 0 on success and returns an error number on failure.
*/
int pthread_key_delete(pthread_key_t __key);
int pthread_mutexattr_destroy(pthread_mutexattr_t* _Nonnull __attr);