pthread_internal.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-10-26 Bernard the first version
  9. */
  10. #ifndef __PTHREAD_INTERNAL_H__
  11. #define __PTHREAD_INTERNAL_H__
  12. #include <rtthread.h>
  13. #include <pthread.h>
  14. struct _pthread_cleanup
  15. {
  16. void (*cleanup_func)(void *parameter);
  17. void *parameter;
  18. struct _pthread_cleanup *next;
  19. };
  20. typedef struct _pthread_cleanup _pthread_cleanup_t;
  21. struct _pthread_key_data
  22. {
  23. int is_used;
  24. void (*destructor)(void *parameter);
  25. };
  26. typedef struct _pthread_key_data _pthread_key_data_t;
  27. #define PTHREAD_MAGIC 0x70746873
  28. struct _pthread_data
  29. {
  30. rt_uint32_t magic;
  31. pthread_attr_t attr;
  32. rt_thread_t tid;
  33. void* (*thread_entry)(void *parameter);
  34. void *thread_parameter;
  35. /* return value */
  36. void *return_value;
  37. /* semaphore for joinable thread */
  38. rt_sem_t joinable_sem;
  39. /* cancel state and type */
  40. rt_uint8_t cancelstate;
  41. volatile rt_uint8_t canceltype;
  42. volatile rt_uint8_t canceled;
  43. _pthread_cleanup_t *cleanup;
  44. void** tls; /* thread-local storage area */
  45. };
  46. typedef struct _pthread_data _pthread_data_t;
  47. rt_inline _pthread_data_t *_pthread_get_data(pthread_t thread)
  48. {
  49. _pthread_data_t *ptd;
  50. RT_ASSERT(thread != RT_NULL);
  51. ptd = (_pthread_data_t *)thread->user_data;
  52. RT_ASSERT(ptd != RT_NULL);
  53. RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
  54. return ptd;
  55. }
  56. int clock_time_to_tick(const struct timespec *time);
  57. void posix_mq_system_init(void);
  58. void posix_sem_system_init(void);
  59. void pthread_key_system_init(void);
  60. #endif