Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Intel Corporation |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 7 | #ifndef ZEPHYR_INCLUDE_POSIX_PTHREAD_H_ |
| 8 | #define ZEPHYR_INCLUDE_POSIX_PTHREAD_H_ |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 9 | |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 10 | #include <kernel.h> |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 11 | #include <wait_q.h> |
Ramakrishna Pallala | f603e60 | 2018-04-05 22:41:15 +0530 | [diff] [blame] | 12 | #include <posix/time.h> |
| 13 | #include <posix/unistd.h> |
Youvedeep Singh | abc94b8 | 2018-01-03 15:38:02 +0530 | [diff] [blame] | 14 | #include "sys/types.h" |
Youvedeep Singh | 7eabf10 | 2018-01-13 18:51:15 +0530 | [diff] [blame] | 15 | #include "posix_sched.h" |
Niranjhana N | 414c39f | 2018-04-11 16:00:09 +0530 | [diff] [blame] | 16 | #include <posix/pthread_key.h> |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 19 | |
| 20 | enum pthread_state { |
| 21 | /* The thread is running and joinable. */ |
| 22 | PTHREAD_JOINABLE = 0, |
| 23 | /* The thread is running and detached. */ |
| 24 | PTHREAD_DETACHED, |
| 25 | /* A joinable thread exited and its return code is available. */ |
| 26 | PTHREAD_EXITED, |
| 27 | /* The thread structure is unallocated and available for reuse. */ |
| 28 | PTHREAD_TERMINATED |
| 29 | }; |
| 30 | |
| 31 | struct posix_thread { |
| 32 | struct k_thread thread; |
| 33 | |
Niranjhana N | 414c39f | 2018-04-11 16:00:09 +0530 | [diff] [blame] | 34 | /* List of keys that thread has called pthread_setspecific() on */ |
| 35 | sys_slist_t key_list; |
| 36 | |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 37 | /* Exit status */ |
| 38 | void *retval; |
| 39 | |
| 40 | /* Pthread cancellation */ |
| 41 | int cancel_state; |
| 42 | int cancel_pending; |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 43 | pthread_mutex_t cancel_lock; |
| 44 | |
| 45 | /* Pthread State */ |
| 46 | enum pthread_state state; |
| 47 | pthread_mutex_t state_lock; |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 48 | pthread_cond_t state_cond; |
| 49 | }; |
| 50 | |
| 51 | /* Pthread detach/joinable */ |
| 52 | #define PTHREAD_CREATE_JOINABLE 0 |
| 53 | #define PTHREAD_CREATE_DETACHED 1 |
| 54 | |
| 55 | /* Pthread cancellation */ |
| 56 | #define _PTHREAD_CANCEL_POS 0 |
| 57 | #define PTHREAD_CANCEL_ENABLE (0 << _PTHREAD_CANCEL_POS) |
| 58 | #define PTHREAD_CANCEL_DISABLE (1 << _PTHREAD_CANCEL_POS) |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 59 | |
Niranjhana N | 414c39f | 2018-04-11 16:00:09 +0530 | [diff] [blame] | 60 | /* Passed to pthread_once */ |
| 61 | #define PTHREAD_ONCE_INIT 1 |
| 62 | |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 63 | /** |
| 64 | * @brief Declare a pthread condition variable |
| 65 | * |
| 66 | * Declaration API for a pthread condition variable. This is not a |
| 67 | * POSIX API, it's provided to better conform with Zephyr's allocation |
| 68 | * strategies for kernel objects. |
| 69 | * |
| 70 | * @param name Symbol name of the condition variable |
| 71 | */ |
| 72 | #define PTHREAD_COND_DEFINE(name) \ |
| 73 | struct pthread_cond name = { \ |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 74 | .wait_q = _WAIT_Q_INIT(&name.wait_q), \ |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @brief POSIX threading compatibility API |
| 79 | * |
| 80 | * See IEEE 1003.1 |
| 81 | */ |
| 82 | static inline int pthread_cond_init(pthread_cond_t *cv, |
| 83 | const pthread_condattr_t *att) |
| 84 | { |
| 85 | ARG_UNUSED(att); |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 86 | _waitq_init(&cv->wait_q); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @brief POSIX threading compatibility API |
| 92 | * |
| 93 | * See IEEE 1003.1 |
| 94 | */ |
| 95 | static inline int pthread_cond_destroy(pthread_cond_t *cv) |
| 96 | { |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @brief POSIX threading compatibility API |
| 102 | * |
| 103 | * See IEEE 1003.1 |
| 104 | */ |
| 105 | int pthread_cond_signal(pthread_cond_t *cv); |
| 106 | |
| 107 | /** |
| 108 | * @brief POSIX threading compatibility API |
| 109 | * |
| 110 | * See IEEE 1003.1 |
| 111 | */ |
| 112 | int pthread_cond_broadcast(pthread_cond_t *cv); |
| 113 | |
| 114 | /** |
| 115 | * @brief POSIX threading compatibility API |
| 116 | * |
| 117 | * See IEEE 1003.1 |
| 118 | */ |
| 119 | int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut); |
| 120 | |
| 121 | /** |
| 122 | * @brief POSIX threading compatibility API |
| 123 | * |
| 124 | * See IEEE 1003.1 |
| 125 | */ |
| 126 | int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mut, |
| 127 | const struct timespec *to); |
| 128 | |
| 129 | /** |
| 130 | * @brief POSIX threading compatibility API |
| 131 | * |
| 132 | * See IEEE 1003.1. |
| 133 | * |
| 134 | * Note that pthread attribute structs are currently noops in Zephyr. |
| 135 | */ |
| 136 | static inline int pthread_condattr_init(pthread_condattr_t *att) |
| 137 | { |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @brief POSIX threading compatibility API |
| 143 | * |
| 144 | * See IEEE 1003.1 |
| 145 | * |
| 146 | * Note that pthread attribute structs are currently noops in Zephyr. |
| 147 | */ |
| 148 | static inline int pthread_condattr_destroy(pthread_condattr_t *att) |
| 149 | { |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @brief Declare a pthread mutex |
| 155 | * |
| 156 | * Declaration API for a pthread mutex. This is not a POSIX API, it's |
| 157 | * provided to better conform with Zephyr's allocation strategies for |
| 158 | * kernel objects. |
| 159 | * |
| 160 | * @param name Symbol name of the mutex |
| 161 | */ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 162 | #define PTHREAD_MUTEX_DEFINE(name) \ |
| 163 | struct pthread_mutex name \ |
| 164 | __in_section(_k_mutex, static, name) = \ |
| 165 | { \ |
| 166 | .lock_count = 0, \ |
Andy Ross | f4b6daf | 2018-05-18 17:33:16 -0700 | [diff] [blame] | 167 | .wait_q = _WAIT_Q_INIT(&name.wait_q), \ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 168 | .owner = NULL, \ |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 171 | /* |
| 172 | * Mutex attributes - type |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 173 | * |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 174 | * PTHREAD_MUTEX_NORMAL: Owner of mutex cannot relock it. Attempting |
| 175 | * to relock will cause deadlock. |
| 176 | * PTHREAD_MUTEX_RECURSIVE: Owner can relock the mutex. |
| 177 | * PTHREAD_MUTEX_ERRORCHECK: If owner attempts to relock the mutex, an |
| 178 | * error is returned. |
| 179 | * |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 180 | */ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 181 | #define PTHREAD_MUTEX_NORMAL 0 |
| 182 | #define PTHREAD_MUTEX_RECURSIVE 1 |
| 183 | #define PTHREAD_MUTEX_ERRORCHECK 2 |
| 184 | #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 185 | |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 186 | /* |
| 187 | * Mutex attributes - protocol |
| 188 | * |
| 189 | * PTHREAD_PRIO_NONE: Ownership of mutex does not affect priority. |
| 190 | * PTHREAD_PRIO_INHERIT: Owner's priority is boosted to the priority of |
| 191 | * highest priority thread blocked on the mutex. |
| 192 | * PTHREAD_PRIO_PROTECT: Mutex has a priority ceiling. The owner's |
| 193 | * priority is boosted to the highest priority ceiling of all mutexes |
| 194 | * owned (regardless of whether or not other threads are blocked on |
| 195 | * any of these mutexes). |
| 196 | * FIXME: Only PRIO_NONE is supported. Implement other protocols. |
| 197 | */ |
| 198 | #define PTHREAD_PRIO_NONE 0 |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 199 | |
| 200 | /** |
| 201 | * @brief POSIX threading compatibility API |
| 202 | * |
| 203 | * See IEEE 1003.1 |
| 204 | */ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 205 | int pthread_mutex_destroy(pthread_mutex_t *m); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * @brief POSIX threading compatibility API |
| 209 | * |
| 210 | * See IEEE 1003.1 |
| 211 | */ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 212 | int pthread_mutex_lock(pthread_mutex_t *m); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * @brief POSIX threading compatibility API |
| 216 | * |
| 217 | * See IEEE 1003.1 |
| 218 | */ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 219 | int pthread_mutex_unlock(pthread_mutex_t *m); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 220 | |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 221 | /** |
| 222 | * @brief POSIX threading compatibility API |
| 223 | * |
| 224 | * See IEEE 1003.1 |
| 225 | */ |
| 226 | |
| 227 | int pthread_mutex_timedlock(pthread_mutex_t *m, |
| 228 | const struct timespec *to); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * @brief POSIX threading compatibility API |
| 232 | * |
| 233 | * See IEEE 1003.1 |
| 234 | */ |
| 235 | int pthread_mutex_trylock(pthread_mutex_t *m); |
| 236 | |
| 237 | /** |
| 238 | * @brief POSIX threading compatibility API |
| 239 | * |
| 240 | * See IEEE 1003.1 |
| 241 | */ |
Punit Vara | eb8ba69 | 2018-05-03 15:24:08 +0530 | [diff] [blame] | 242 | int pthread_mutex_init(pthread_mutex_t *m, |
| 243 | const pthread_mutexattr_t *att); |
| 244 | |
| 245 | /** |
| 246 | * @brief POSIX threading compatibility API |
| 247 | * |
| 248 | * See IEEE 1003.1 |
| 249 | */ |
| 250 | int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol); |
| 251 | |
| 252 | /** |
| 253 | * @brief POSIX threading compatibility API |
| 254 | * |
| 255 | * See IEEE 1003.1 |
| 256 | */ |
| 257 | int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); |
| 258 | |
| 259 | /** |
| 260 | * @brief POSIX threading compatibility API |
| 261 | * |
| 262 | * See IEEE 1003.1 |
| 263 | */ |
| 264 | int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, |
| 265 | int *protocol); |
| 266 | |
| 267 | /** |
| 268 | * @brief POSIX threading compatibility API |
| 269 | * |
| 270 | * See IEEE 1003.1 |
| 271 | */ |
| 272 | int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * @brief POSIX threading compatibility API |
| 276 | * |
| 277 | * See IEEE 1003.1 |
| 278 | * |
| 279 | * Note that pthread attribute structs are currently noops in Zephyr. |
| 280 | */ |
| 281 | static inline int pthread_mutexattr_init(pthread_mutexattr_t *m) |
| 282 | { |
| 283 | ARG_UNUSED(m); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * @brief POSIX threading compatibility API |
| 290 | * |
| 291 | * See IEEE 1003.1 |
| 292 | * |
| 293 | * Note that pthread attribute structs are currently noops in Zephyr. |
| 294 | */ |
| 295 | static inline int pthread_mutexattr_destroy(pthread_mutexattr_t *m) |
| 296 | { |
| 297 | ARG_UNUSED(m); |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | /* FIXME: these are going to be tricky to implement. Zephyr has (for |
| 303 | * good reason) deprecated its own "initializer" macros in favor of a |
| 304 | * static "declaration" macros instead. Using such a macro inside a |
| 305 | * gcc compound expression to declare and object then reference it |
| 306 | * would work, but gcc limits such expressions to function context |
| 307 | * (because they may need to generate code that runs at assignment |
| 308 | * time) and much real-world use of these initializers is for static |
| 309 | * variables. The best trick I can think of would be to declare it in |
| 310 | * a special section and then initialize that section at runtime |
| 311 | * startup, which sort of defeats the purpose of having these be |
| 312 | * static... |
| 313 | * |
| 314 | * Instead, see the nonstandard PTHREAD_*_DEFINE macros instead, which |
| 315 | * work similarly but conform to Zephyr's paradigms. |
| 316 | */ |
| 317 | /* #define PTHREAD_MUTEX_INITIALIZER */ |
| 318 | /* #define PTHREAD_COND_INITIALIZER */ |
| 319 | |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 320 | /** |
| 321 | * @brief Declare a pthread barrier |
| 322 | * |
| 323 | * Declaration API for a pthread barrier. This is not a |
| 324 | * POSIX API, it's provided to better conform with Zephyr's allocation |
| 325 | * strategies for kernel objects. |
| 326 | * |
| 327 | * @param name Symbol name of the barrier |
| 328 | * @param count Thread count, same as the "count" argument to |
| 329 | * pthread_barrier_init() |
| 330 | */ |
| 331 | #define PTHREAD_BARRIER_DEFINE(name, count) \ |
| 332 | struct pthread_barrier name = { \ |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 333 | .wait_q = _WAIT_Q_INIT(&name.wait_q), \ |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 334 | .max = count, \ |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * @brief POSIX threading compatibility API |
| 339 | * |
| 340 | * See IEEE 1003.1 |
| 341 | */ |
| 342 | int pthread_barrier_wait(pthread_barrier_t *b); |
| 343 | |
| 344 | /** |
| 345 | * @brief POSIX threading compatibility API |
| 346 | * |
| 347 | * See IEEE 1003.1 |
| 348 | */ |
| 349 | static inline int pthread_barrier_init(pthread_barrier_t *b, |
| 350 | const pthread_barrierattr_t *attr, |
| 351 | unsigned int count) |
| 352 | { |
| 353 | ARG_UNUSED(attr); |
| 354 | |
| 355 | b->max = count; |
| 356 | b->count = 0; |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 357 | _waitq_init(&b->wait_q); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * @brief POSIX threading compatibility API |
| 364 | * |
| 365 | * See IEEE 1003.1 |
| 366 | */ |
| 367 | static inline int pthread_barrier_destroy(pthread_barrier_t *b) |
| 368 | { |
| 369 | ARG_UNUSED(b); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * @brief POSIX threading compatibility API |
| 376 | * |
| 377 | * See IEEE 1003.1 |
| 378 | * |
| 379 | * Note that pthread attribute structs are currently noops in Zephyr. |
| 380 | */ |
| 381 | static inline int pthread_barrierattr_init(pthread_barrierattr_t *b) |
| 382 | { |
| 383 | ARG_UNUSED(b); |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * @brief POSIX threading compatibility API |
| 390 | * |
| 391 | * See IEEE 1003.1 |
| 392 | * |
| 393 | * Note that pthread attribute structs are currently noops in Zephyr. |
| 394 | */ |
| 395 | static inline int pthread_barrierattr_destroy(pthread_barrierattr_t *b) |
| 396 | { |
| 397 | ARG_UNUSED(b); |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | /* Predicates and setters for various pthread attribute values that we |
| 403 | * don't support (or always support: the "process shared" attribute |
| 404 | * can only be true given the way Zephyr implements these |
| 405 | * objects). Leave these undefined for simplicity instead of defining |
| 406 | * stubs to return an error that would have to be logged and |
| 407 | * interpreted just to figure out that we didn't support it in the |
| 408 | * first place. These APIs are very rarely used even in production |
| 409 | * Unix code. Leave the declarations here so they can be easily |
| 410 | * uncommented and implemented as needed. |
| 411 | |
| 412 | int pthread_condattr_getclock(const pthread_condattr_t * clockid_t *); |
| 413 | int pthread_condattr_getpshared(const pthread_condattr_t * int *); |
| 414 | int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); |
| 415 | int pthread_condattr_setpshared(pthread_condattr_t *, int); |
| 416 | int pthread_mutex_consistent(pthread_mutex_t *); |
| 417 | int pthread_mutex_getprioceiling(const pthread_mutex_t * int *); |
| 418 | int pthread_mutex_setprioceiling(pthread_mutex_t *, int int *); |
| 419 | int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *, int *); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 420 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t * int *); |
| 421 | int pthread_mutexattr_getrobust(const pthread_mutexattr_t * int *); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 422 | int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 423 | int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); |
| 424 | int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); |
Andy Ross | 53c8599 | 2017-07-24 14:59:55 -0700 | [diff] [blame] | 425 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *); |
| 426 | int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); |
| 427 | */ |
| 428 | |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 429 | /* Base Pthread related APIs */ |
| 430 | |
| 431 | /** |
| 432 | * @brief Obtain ID of the calling thread. |
| 433 | * |
| 434 | * The results of calling this API from threads not created with |
| 435 | * pthread_create() are undefined. |
| 436 | * |
| 437 | * See IEEE 1003.1 |
| 438 | */ |
| 439 | static inline pthread_t pthread_self(void) |
| 440 | { |
| 441 | return (pthread_t)k_current_get(); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /** |
| 446 | * @brief Compare thread IDs. |
| 447 | * |
| 448 | * See IEEE 1003.1 |
| 449 | */ |
| 450 | static inline int pthread_equal(pthread_t pt1, pthread_t pt2) |
| 451 | { |
| 452 | return (pt1 == pt2); |
| 453 | } |
| 454 | |
Youvedeep Singh | 216883c | 2018-02-28 15:37:00 +0530 | [diff] [blame] | 455 | /** |
| 456 | * @brief Destroy the read-write lock attributes object. |
| 457 | * |
| 458 | * See IEEE 1003.1 |
| 459 | */ |
| 460 | static inline int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) |
| 461 | { |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * @brief initialize the read-write lock attributes object. |
| 467 | * |
| 468 | * See IEEE 1003.1 |
| 469 | */ |
| 470 | static inline int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) |
| 471 | { |
| 472 | return 0; |
| 473 | } |
| 474 | |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 475 | int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); |
| 476 | int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); |
| 477 | int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy); |
| 478 | int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); |
| 479 | int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); |
| 480 | int pthread_attr_init(pthread_attr_t *attr); |
| 481 | int pthread_attr_destroy(pthread_attr_t *attr); |
| 482 | int pthread_attr_getschedparam(const pthread_attr_t *attr, |
| 483 | struct sched_param *schedparam); |
| 484 | int pthread_getschedparam(pthread_t pthread, int *policy, |
| 485 | struct sched_param *param); |
| 486 | int pthread_attr_getstack(const pthread_attr_t *attr, |
| 487 | void **stackaddr, size_t *stacksize); |
| 488 | int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, |
| 489 | size_t stacksize); |
Niranjhana N | 414c39f | 2018-04-11 16:00:09 +0530 | [diff] [blame] | 490 | int pthread_once(pthread_once_t *once, void (*initFunc)(void)); |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 491 | void pthread_exit(void *retval); |
| 492 | int pthread_join(pthread_t thread, void **status); |
| 493 | int pthread_cancel(pthread_t pthread); |
| 494 | int pthread_detach(pthread_t thread); |
| 495 | int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, |
| 496 | void *(*threadroutine)(void *), void *arg); |
| 497 | int pthread_setcancelstate(int state, int *oldstate); |
| 498 | int pthread_attr_setschedparam(pthread_attr_t *attr, |
| 499 | const struct sched_param *schedparam); |
| 500 | int pthread_setschedparam(pthread_t pthread, int policy, |
| 501 | const struct sched_param *param); |
Youvedeep Singh | 216883c | 2018-02-28 15:37:00 +0530 | [diff] [blame] | 502 | int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); |
| 503 | int pthread_rwlock_init(pthread_rwlock_t *rwlock, |
| 504 | const pthread_rwlockattr_t *attr); |
| 505 | int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); |
| 506 | int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, |
| 507 | const struct timespec *abstime); |
| 508 | int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, |
| 509 | const struct timespec *abstime); |
| 510 | int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); |
| 511 | int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); |
| 512 | int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); |
| 513 | int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); |
Niranjhana N | 414c39f | 2018-04-11 16:00:09 +0530 | [diff] [blame] | 514 | int pthread_key_create(pthread_key_t *key, |
| 515 | void (*destructor)(void *)); |
| 516 | int pthread_key_delete(pthread_key_t key); |
| 517 | int pthread_setspecific(pthread_key_t key, const void *value); |
| 518 | void *pthread_getspecific(pthread_key_t key); |
Youvedeep Singh | c8aa657 | 2017-12-28 14:31:57 +0530 | [diff] [blame] | 519 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 520 | #endif /* ZEPHYR_INCLUDE_POSIX_PTHREAD_H_ */ |