pthread.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <sched.h>
  28. #include <stdint.h>
  29. #include <sys/cdefs.h>
  30. #include <sys/types.h>
  31. #include <time.h>
  32. __BEGIN_DECLS
  33. int pthread_create(pthread_t*, pthread_attr_t*, void* (*)(void*), void*);
  34. void pthread_exit(void*) __attribute__((noreturn));
  35. int pthread_kill(pthread_t, int);
  36. void pthread_cleanup_push(void (*)(void*), void*);
  37. void pthread_cleanup_pop(int);
  38. int pthread_join(pthread_t, void**);
  39. int pthread_mutex_lock(pthread_mutex_t*);
  40. int pthread_mutex_trylock(pthread_mutex_t* mutex);
  41. int pthread_mutex_unlock(pthread_mutex_t*);
  42. int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*);
  43. int pthread_mutex_destroy(pthread_mutex_t*);
  44. int pthread_attr_init(pthread_attr_t*);
  45. int pthread_attr_destroy(pthread_attr_t*);
  46. #define PTHREAD_CREATE_JOINABLE 0
  47. #define PTHREAD_CREATE_DETACHED 1
  48. int pthread_attr_getdetachstate(const pthread_attr_t*, int*);
  49. int pthread_attr_setdetachstate(pthread_attr_t*, int);
  50. int pthread_attr_getguardsize(const pthread_attr_t*, size_t*);
  51. int pthread_attr_setguardsize(pthread_attr_t*, size_t);
  52. int pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*);
  53. int pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*);
  54. int pthread_attr_getstack(const pthread_attr_t*, void**, size_t*);
  55. int pthread_attr_setstack(pthread_attr_t* attr, void*, size_t);
  56. int pthread_attr_getstacksize(const pthread_attr_t*, size_t*);
  57. int pthread_attr_setstacksize(pthread_attr_t*, size_t);
  58. int pthread_once(pthread_once_t*, void (*)(void));
  59. #define PTHREAD_ONCE_INIT 0
  60. void* pthread_getspecific(pthread_key_t key);
  61. int pthread_setspecific(pthread_key_t key, const void* value);
  62. int pthread_getschedparam(pthread_t thread, int* policy, struct sched_param* param);
  63. int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param* param);
  64. #define PTHREAD_MUTEX_NORMAL 0
  65. #define PTHREAD_MUTEX_RECURSIVE 1
  66. #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
  67. #define PTHREAD_MUTEX_INITIALIZER \
  68. { \
  69. 0, 0, 0, PTHREAD_MUTEX_DEFAULT \
  70. }
  71. #define PTHREAD_COND_INITIALIZER \
  72. { \
  73. 0, 0, CLOCK_MONOTONIC_COARSE \
  74. }
  75. int pthread_key_create(pthread_key_t* key, void (*destructor)(void*));
  76. int pthread_key_delete(pthread_key_t key);
  77. int pthread_cond_broadcast(pthread_cond_t*);
  78. int pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*);
  79. int pthread_cond_signal(pthread_cond_t*);
  80. int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*);
  81. int pthread_condattr_init(pthread_condattr_t*);
  82. int pthread_condattr_setclock(pthread_condattr_t*, clockid_t);
  83. int pthread_condattr_destroy(pthread_condattr_t*);
  84. int pthread_cancel(pthread_t);
  85. int pthread_cond_destroy(pthread_cond_t*);
  86. int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
  87. void pthread_testcancel(void);
  88. int pthread_spin_destroy(pthread_spinlock_t*);
  89. int pthread_spin_init(pthread_spinlock_t*, int);
  90. int pthread_spin_lock(pthread_spinlock_t*);
  91. int pthread_spin_trylock(pthread_spinlock_t*);
  92. int pthread_spin_unlock(pthread_spinlock_t*);
  93. pthread_t pthread_self(void);
  94. int pthread_detach(pthread_t);
  95. int pthread_equal(pthread_t, pthread_t);
  96. int pthread_mutexattr_init(pthread_mutexattr_t*);
  97. int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
  98. int pthread_mutexattr_destroy(pthread_mutexattr_t*);
  99. int pthread_setname_np(pthread_t, const char*);
  100. int pthread_getname_np(pthread_t, char*, size_t);
  101. __END_DECLS