pthread_internal.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef __PTHREAD_INTERNAL_H__
  2. #define __PTHREAD_INTERNAL_H__
  3. #include <rtthread.h>
  4. #include <pthread.h>
  5. struct _pthread_cleanup
  6. {
  7. void (*cleanup_func)(void* parameter);
  8. void* parameter;
  9. struct _pthread_cleanup* next;
  10. };
  11. typedef struct _pthread_cleanup _pthread_cleanup_t;
  12. struct _pthread_key_data
  13. {
  14. int is_used;
  15. void (*destructor)(void* parameter);
  16. };
  17. typedef struct _pthread_key_data _pthread_key_data_t;
  18. #define PTHREAD_MAGIC 0x70746873
  19. struct _pthread_data
  20. {
  21. rt_uint32_t magic;
  22. pthread_attr_t attr;
  23. rt_thread_t tid;
  24. void* (*thread_entry)(void* parameter);
  25. void* thread_parameter;
  26. /* return value */
  27. void* return_value;
  28. /* semaphore for joinable thread */
  29. rt_sem_t joinable_sem;
  30. /* cancel state and type */
  31. rt_uint8_t cancelstate;
  32. volatile rt_uint8_t canceltype;
  33. volatile rt_uint8_t canceled;
  34. _pthread_cleanup_t* cleanup;
  35. void** tls; /* thread-local storage area */
  36. };
  37. typedef struct _pthread_data _pthread_data_t;
  38. rt_inline _pthread_data_t* _pthread_get_data(pthread_t thread)
  39. {
  40. _pthread_data_t* ptd;
  41. RT_ASSERT(thread != RT_NULL);
  42. ptd = (_pthread_data_t*)thread->user_data;
  43. RT_ASSERT(ptd != RT_NULL);
  44. RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
  45. return ptd;
  46. }
  47. int clock_time_to_tick(const struct timespec *time);
  48. void clock_time_system_init(void);
  49. void posix_mq_system_init(void);
  50. void posix_sem_system_init(void);
  51. void pthread_key_system_init(void);
  52. #endif