1cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh/*
2cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * Copyright (C) 2008 The Android Open Source Project
3cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * All rights reserved.
4cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *
5cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * Redistribution and use in source and binary forms, with or without
6cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * modification, are permitted provided that the following conditions
7cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * are met:
8cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *  * Redistributions of source code must retain the above copyright
9cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *    notice, this list of conditions and the following disclaimer.
10cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *  * Redistributions in binary form must reproduce the above copyright
11cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *    notice, this list of conditions and the following disclaimer in
12cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *    the documentation and/or other materials provided with the
13cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *    distribution.
14cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh *
15cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * SUCH DAMAGE.
27cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh */
28cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
29cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#ifndef _PTHREAD_H_
30cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define _PTHREAD_H_
31cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
32cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#include <time.h>
33cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#include <signal.h>
34cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#include <sched.h>
35cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#include <limits.h>
36cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#include <sys/types.h>
37cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
3814c2fbd9d075cf4214e83beb231f376bbc7604e1Andrew Hsieh#if defined(__LP64__)
391b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh  #define __RESERVED_INITIALIZER , {0}
401b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#else
411b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh  #define __RESERVED_INITIALIZER
421b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#endif
431b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh
44cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef struct {
45cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  int volatile value;
461b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#ifdef __LP64__
471b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh  char __reserved[36];
481b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#endif
49cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh} pthread_mutex_t;
50cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
51cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define  __PTHREAD_MUTEX_INIT_VALUE            0
52cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define  __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE  0x4000
53cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define  __PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE 0x8000
54cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
551b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#define  PTHREAD_MUTEX_INITIALIZER             {__PTHREAD_MUTEX_INIT_VALUE __RESERVED_INITIALIZER}
561b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#define  PTHREAD_RECURSIVE_MUTEX_INITIALIZER   {__PTHREAD_RECURSIVE_MUTEX_INIT_VALUE __RESERVED_INITIALIZER}
571b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#define  PTHREAD_ERRORCHECK_MUTEX_INITIALIZER  {__PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE __RESERVED_INITIALIZER}
58cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
59cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehenum {
60cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    PTHREAD_MUTEX_NORMAL = 0,
61cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    PTHREAD_MUTEX_RECURSIVE = 1,
62cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    PTHREAD_MUTEX_ERRORCHECK = 2,
63cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
64cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK,
65cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    PTHREAD_MUTEX_RECURSIVE_NP  = PTHREAD_MUTEX_RECURSIVE,
66cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
67cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
68cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh};
69cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
70cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef struct {
71cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  int volatile value;
721b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#ifdef __LP64__
731b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh  char __reserved[44];
741b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#endif
75cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh} pthread_cond_t;
76cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
771b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#define PTHREAD_COND_INITIALIZER  {0 __RESERVED_INITIALIZER}
78cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
79cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef struct {
80cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  uint32_t flags;
81cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  void* stack_base;
82cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  size_t stack_size;
83cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  size_t guard_size;
84cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  int32_t sched_policy;
85cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  int32_t sched_priority;
861b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#ifdef __LP64__
871b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh  char __reserved[16];
881b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#endif
89cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh} pthread_attr_t;
90cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
91cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef long pthread_mutexattr_t;
92cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef long pthread_condattr_t;
93cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
941b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsiehtypedef long pthread_rwlockattr_t;
95cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
96cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef struct {
97244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#if !defined(__LP64__)
98244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  pthread_mutex_t __unused_lock;
99244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  pthread_cond_t __unused_cond;
100244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#endif
101244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  volatile int32_t state; // 0=unlock, -1=writer lock, +n=reader lock
102244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  volatile int32_t writer_thread_id;
103244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  volatile int32_t pending_readers;
104244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  volatile int32_t pending_writers;
105244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  int32_t attr;
106244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#ifdef __LP64__
107244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  char __reserved[36];
108244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#else
109244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  char __reserved[12];
110244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#endif
111244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh
112cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh} pthread_rwlock_t;
113cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
114244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#ifdef __LP64__
115244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  #define PTHREAD_RWLOCK_INITIALIZER  { 0, 0, 0, 0, 0, { 0 } }
116244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#else
117244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh  #define PTHREAD_RWLOCK_INITIALIZER  { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0, 0, { 0 } }
118244dca2ed2a3f87b0f93d23f1bc2ea0ba9c8d783Andrew Hsieh#endif
119cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
120cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef int pthread_key_t;
121cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef long pthread_t;
122cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
123cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef volatile int pthread_once_t;
124cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
1251b1d56acc5281d0201fdbe8539012a2dbf09bc8fAndrew Hsieh#define PTHREAD_ONCE_INIT 0
126cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
12714c2fbd9d075cf4214e83beb231f376bbc7604e1Andrew Hsieh#if defined(__LP64__)
12814c2fbd9d075cf4214e83beb231f376bbc7604e1Andrew Hsieh#define PTHREAD_STACK_MIN (4 * PAGE_SIZE)
12914c2fbd9d075cf4214e83beb231f376bbc7604e1Andrew Hsieh#else
130cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_STACK_MIN (2 * PAGE_SIZE)
13114c2fbd9d075cf4214e83beb231f376bbc7604e1Andrew Hsieh#endif
132cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
133cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_CREATE_DETACHED  0x00000001
134cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_CREATE_JOINABLE  0x00000000
135cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
136cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_PROCESS_PRIVATE  0
137cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_PROCESS_SHARED   1
138cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
139cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_SCOPE_SYSTEM     0
140cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define PTHREAD_SCOPE_PROCESS    1
141cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
142cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh__BEGIN_DECLS
143cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
144cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_atfork(void (*)(void), void (*)(void), void(*)(void));
145cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
146cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_destroy(pthread_attr_t*) __nonnull((1));
147cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getdetachstate(const pthread_attr_t*, int*) __nonnull((1, 2));
148cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getguardsize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
149cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*) __nonnull((1, 2));
150cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getschedpolicy(const pthread_attr_t*, int*) __nonnull((1, 2));
151cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getscope(const pthread_attr_t*, int*) __nonnull((1, 2));
152cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getstack(const pthread_attr_t*, void**, size_t*) __nonnull((1, 2, 3));
153cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_getstacksize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
154cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_init(pthread_attr_t*) __nonnull((1));
155cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_setdetachstate(pthread_attr_t*, int) __nonnull((1));
156cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_setguardsize(pthread_attr_t*, size_t) __nonnull((1));
157cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*) __nonnull((1, 2));
158cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1));
159cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1));
160cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1));
161b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_attr_setstacksize(pthread_attr_t*, size_t stack_size) __nonnull((1));
162cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
163cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1));
164b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2));
165cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2));
166cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_condattr_init(pthread_condattr_t*) __nonnull((1));
167b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1));
168cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
169cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
170cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
171cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_destroy(pthread_cond_t*) __nonnull((1));
172cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*) __nonnull((1));
173cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_signal(pthread_cond_t*) __nonnull((1));
174cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __nonnull((1, 2, 3));
175cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*) __nonnull((1, 2));
176cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
177cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_create(pthread_t*, pthread_attr_t const*, void *(*)(void*), void*) __nonnull((1, 3));
178cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_detach(pthread_t);
179cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehvoid pthread_exit(void*) __noreturn;
180cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
181cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_equal(pthread_t, pthread_t);
182cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
183cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_getattr_np(pthread_t, pthread_attr_t*) __nonnull((2));
184cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
185cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_getcpuclockid(pthread_t, clockid_t*) __nonnull((2));
186cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
187cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3));
188cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
189cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehvoid* pthread_getspecific(pthread_key_t);
190cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
191239fbd351e885fa6844a674255b79d1d81c3682aAndrew Hsiehpid_t pthread_gettid_np(pthread_t);
192239fbd351e885fa6844a674255b79d1d81c3682aAndrew Hsieh
193cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_join(pthread_t, void**);
194cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
195cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
196cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_key_delete(pthread_key_t);
197cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
198cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_kill(pthread_t, int);
199cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
200cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1));
201cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
202cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
203cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutexattr_init(pthread_mutexattr_t*) __nonnull((1));
204cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutexattr_setpshared(pthread_mutexattr_t*, int) __nonnull((1));
205cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutexattr_settype(pthread_mutexattr_t*, int) __nonnull((1));
206cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
207cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
208cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
209cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
210b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2));
211cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
212cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
213cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
214cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2));
215cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
216cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlockattr_destroy(pthread_rwlockattr_t*) __nonnull((1));
217cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
218cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlockattr_init(pthread_rwlockattr_t*) __nonnull((1));
219cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int) __nonnull((1));
220cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
221cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_destroy(pthread_rwlock_t*) __nonnull((1));
222cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_init(pthread_rwlock_t*, const pthread_rwlockattr_t*) __nonnull((1));
223cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_rdlock(pthread_rwlock_t*) __nonnull((1));
224cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_timedrdlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
225cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_timedwrlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
226cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_tryrdlock(pthread_rwlock_t*) __nonnull((1));
227cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1));
228cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_unlock(pthread_rwlock_t *rwlock) __nonnull((1));
229cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
230cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
2311b55d7b281f282232ee58da5d09d3da5969ff11dAndrew Hsiehpthread_t pthread_self(void) __pure2;
232cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
233cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_setname_np(pthread_t, const char*) __nonnull((2));
234cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
235cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((3));
236cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
237cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_setspecific(pthread_key_t, const void*);
238cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
239cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_sigmask(int, const sigset_t*, sigset_t*);
240cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
241cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef void (*__pthread_cleanup_func_t)(void*);
242cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
243cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehtypedef struct __pthread_cleanup_t {
244cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  struct __pthread_cleanup_t*   __cleanup_prev;
245cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  __pthread_cleanup_func_t      __cleanup_routine;
246cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh  void*                         __cleanup_arg;
247cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh} __pthread_cleanup_t;
248cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
249cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehextern void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*);
250cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehextern void __pthread_cleanup_pop(__pthread_cleanup_t*, int);
251cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
252cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh/* Believe or not, the definitions of pthread_cleanup_push and
253cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * pthread_cleanup_pop below are correct. Posix states that these
254cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * can be implemented as macros that might introduce opening and
255cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * closing braces, and that using setjmp/longjmp/return/break/continue
256cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh * between them results in undefined behavior.
257cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh */
258cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define  pthread_cleanup_push(routine, arg)                      \
259cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    do {                                                         \
260cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh        __pthread_cleanup_t  __cleanup;                          \
261cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh        __pthread_cleanup_push( &__cleanup, (routine), (arg) );  \
262cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
263cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#define  pthread_cleanup_pop(execute)                  \
264cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh        __pthread_cleanup_pop( &__cleanup, (execute)); \
265cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh    } while (0);                                       \
266cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
267cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
268cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#if !defined(__LP64__)
269cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
270b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsieh// Bionic additions that are deprecated even in the 32-bit ABI.
271b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsieh//
272b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsieh// TODO: Remove them once chromium_org / NFC have switched over.
273cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
274cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsiehint pthread_cond_timedwait_monotonic(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
275cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
276b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
277b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsieh#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 /* TODO: stop defining this to push LP32 off this API sooner. */
278b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
279cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
280b193073d2e5369d848d2135d5a2f642f3242cf0eAndrew Hsiehint pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead")));
281cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
282cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#endif /* !defined(__LP64__) */
283cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
284cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh__END_DECLS
285cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh
286cf138744ee2efefa4cd02ace5bedcdc56d750ad5Andrew Hsieh#endif /* _PTHREAD_H_ */
287