Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.2 KiB

  1. /***
  2. *tidtable.c - Access thread data table
  3. *
  4. * Copyright (c) 1989-1993, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This module contains the following routines for multi-thread
  8. * data support:
  9. *
  10. * _mtinit = Initialize the mthread data
  11. * _getptd = get the pointer to the per-thread data structure for
  12. * the current thread
  13. * _freeptd = free up a per-thread data structure and its
  14. * subordinate structures
  15. * __threadid = return thread ID for the current thread
  16. * __threadhandle = return pseudo-handle for the current thread
  17. *
  18. *Revision History:
  19. * 05-04-90 JCR Translated from ASM to C for portable 32-bit OS/2
  20. * 06-04-90 GJF Changed error message interface.
  21. * 07-02-90 GJF Changed __threadid() for DCR 1024/2012.
  22. * 08-08-90 GJF Removed 32 from API names.
  23. * 10-08-90 GJF New-style function declarators.
  24. * 10-09-90 GJF Thread ids are of type unsigned long! Also, fixed a
  25. * bug in __threadid().
  26. * 10-22-90 GJF Another bug in __threadid().
  27. * 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
  28. * 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
  29. * 05-31-91 GJF Win32 version [_WIN32_].
  30. * 07-18-91 GJF Fixed many errors [_WIN32_].
  31. * 09-29-91 GJF Conditionally added _getptd_lk/_getptd1_lk so that
  32. * DEBUG version of mlock doesn't infinitely recurse
  33. * the first time _THREADDATA_LOCK is asserted [_WIN32_].
  34. * 01-30-92 GJF Must init. _pxcptacttab field to _XcptActTab.
  35. * 02-25-92 GJF Initialize _holdrand field to 1.
  36. * 02-13-93 GJF Revised to use TLS API. Also, purged Cruiser support.
  37. * 03-26-93 GJF Initialize ptd->_holdrand to 1L (see thread.c).
  38. * 04-16-93 SKS Add _mtterm to do multi-thread termination
  39. * Set freed __tlsindex to -1 again to prevent mis-use
  40. * 12-13-93 SKS Add _freeptd(), which frees up the per-thread data
  41. * maintained by the C run-time library.
  42. *
  43. *******************************************************************************/
  44. #include <windows.h>
  45. #include <cruntime.h>
  46. #include <internal.h>
  47. /****
  48. *_mtinit() - Init multi-thread data bases
  49. *
  50. *Purpose:
  51. * (1) Call _mtinitlocks to create/open all lock semaphores.
  52. * (2) Allocate a TLS index to hold pointers to per-thread data
  53. * structure.
  54. *
  55. * NOTES:
  56. * (1) Only to be called ONCE at startup
  57. * (2) Must be called BEFORE any mthread requests are made
  58. *
  59. *Entry:
  60. * <NONE>
  61. *Exit:
  62. * returns TRUE on success
  63. * returns FALSE on failure
  64. * user code should call _amsg_exit if failure is returned
  65. *
  66. *Uses:
  67. * <any registers may be modified at init time>
  68. *
  69. *Exceptions:
  70. *
  71. *******************************************************************************/
  72. int __cdecl _mtinit (
  73. void
  74. )
  75. {
  76. /*
  77. * Initialize the mthread lock data base
  78. */
  79. return _mtinitlocks();
  80. }
  81. /****
  82. *_mtterm() - Clean-up multi-thread data bases
  83. *
  84. *Purpose:
  85. * (1) Call _mtdeletelocks to free up all lock semaphores.
  86. * (2) Free up the TLS index used to hold pointers to
  87. * per-thread data structure.
  88. *
  89. * NOTES:
  90. * (1) Only to be called ONCE at termination
  91. * (2) Must be called AFTER all mthread requests are made
  92. *
  93. *Entry:
  94. * <NONE>
  95. *Exit:
  96. * returns
  97. *
  98. *Uses:
  99. *
  100. *Exceptions:
  101. *
  102. *******************************************************************************/
  103. void __cdecl _mtterm (
  104. void
  105. )
  106. {
  107. /*
  108. * Clean up the mthread lock data base
  109. */
  110. _mtdeletelocks();
  111. }