pthread_init.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * pthread_init.c
  3. *
  4. * Description:
  5. *
  6. * --------------------------------------------------------------------------
  7. *
  8. * Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
  9. * Copyright(C) 2008 Jason Schmidlapp
  10. *
  11. * Contact Email: [email protected]
  12. *
  13. *
  14. * Based upon Pthreads-win32 - POSIX Threads Library for Win32
  15. * Copyright(C) 1998 John E. Bossom
  16. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  17. *
  18. * Contact Email: [email protected]
  19. *
  20. * The original list of contributors to the Pthreads-win32 project
  21. * is contained in the file CONTRIBUTORS.ptw32 included with the
  22. * source code distribution. The list can also be seen at the
  23. * following World Wide Web location:
  24. * http://sources.redhat.com/pthreads-win32/contributors.html
  25. *
  26. * This library is free software; you can redistribute it and/or
  27. * modify it under the terms of the GNU Lesser General Public
  28. * License as published by the Free Software Foundation; either
  29. * version 2 of the License, or (at your option) any later version.
  30. *
  31. * This library is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. * Lesser General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU Lesser General Public
  37. * License along with this library in the file COPYING.LIB;
  38. * if not, write to the Free Software Foundation, Inc.,
  39. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  40. */
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include "pthread.h"
  44. #include "implement.h"
  45. void pthread_init(void)
  46. {
  47. if (pte_processInitialized)
  48. {
  49. /*
  50. * Ignore if already initialized. this is useful for
  51. * programs that uses a non-dll pthread
  52. * library. Such programs must call pte_processInitialize() explicitly,
  53. * since this initialization routine is automatically called only when
  54. * the dll is loaded.
  55. */
  56. return;
  57. }
  58. pte_processInitialized = PTE_TRUE;
  59. // Must happen before creating keys.
  60. pte_osInit();
  61. /*
  62. * Initialize Keys
  63. */
  64. if ((pthread_key_create (&pte_selfThreadKey, NULL) != 0) ||
  65. (pthread_key_create (&pte_cleanupKey, NULL) != 0))
  66. {
  67. pthread_terminate();
  68. }
  69. /*
  70. * Set up the global locks.
  71. */
  72. pte_osMutexCreate (&pte_thread_reuse_lock);
  73. pte_osMutexCreate (&pte_mutex_test_init_lock);
  74. pte_osMutexCreate (&pte_cond_list_lock);
  75. pte_osMutexCreate (&pte_cond_test_init_lock);
  76. pte_osMutexCreate (&pte_rwlock_test_init_lock);
  77. pte_osMutexCreate (&pte_spinlock_test_init_lock);
  78. return;
  79. }