pthread_internal.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * File : pthread_internal.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2010-10-26 Bernard the first version
  23. */
  24. #ifndef __PTHREAD_INTERNAL_H__
  25. #define __PTHREAD_INTERNAL_H__
  26. #include <rtthread.h>
  27. #include <pthread.h>
  28. struct _pthread_cleanup
  29. {
  30. void (*cleanup_func)(void *parameter);
  31. void *parameter;
  32. struct _pthread_cleanup *next;
  33. };
  34. typedef struct _pthread_cleanup _pthread_cleanup_t;
  35. struct _pthread_key_data
  36. {
  37. int is_used;
  38. void (*destructor)(void *parameter);
  39. };
  40. typedef struct _pthread_key_data _pthread_key_data_t;
  41. #define PTHREAD_MAGIC 0x70746873
  42. struct _pthread_data
  43. {
  44. rt_uint32_t magic;
  45. pthread_attr_t attr;
  46. rt_thread_t tid;
  47. void* (*thread_entry)(void *parameter);
  48. void *thread_parameter;
  49. /* return value */
  50. void *return_value;
  51. /* semaphore for joinable thread */
  52. rt_sem_t joinable_sem;
  53. /* cancel state and type */
  54. rt_uint8_t cancelstate;
  55. volatile rt_uint8_t canceltype;
  56. volatile rt_uint8_t canceled;
  57. _pthread_cleanup_t *cleanup;
  58. void** tls; /* thread-local storage area */
  59. };
  60. typedef struct _pthread_data _pthread_data_t;
  61. rt_inline _pthread_data_t *_pthread_get_data(pthread_t thread)
  62. {
  63. _pthread_data_t *ptd;
  64. RT_ASSERT(thread != RT_NULL);
  65. ptd = (_pthread_data_t *)thread->user_data;
  66. RT_ASSERT(ptd != RT_NULL);
  67. RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
  68. return ptd;
  69. }
  70. int clock_time_to_tick(const struct timespec *time);
  71. void posix_mq_system_init(void);
  72. void posix_sem_system_init(void);
  73. void pthread_key_system_init(void);
  74. #endif