Leaked source code of windows server 2003
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.

106 lines
4.2 KiB

  1. // Ruler
  2. // 1 2 3 4 5 6 7 8
  3. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  4. /********************************************************************/
  5. /* */
  6. /* The standard layout. */
  7. /* */
  8. /* The standard layout for 'cpp' files in this code is as */
  9. /* follows: */
  10. /* */
  11. /* 1. Include files. */
  12. /* 2. Constants local to the class. */
  13. /* 3. Data structures local to the class. */
  14. /* 4. Data initializations. */
  15. /* 5. Static functions. */
  16. /* 6. Class functions. */
  17. /* */
  18. /* The constructor is typically the first function, class */
  19. /* member functions appear in alphabetical order with the */
  20. /* destructor appearing at the end of the file. Any section */
  21. /* or function this is not required is simply omitted. */
  22. /* */
  23. /********************************************************************/
  24. #include "LibraryPCH.hpp"
  25. #include "Delay.hpp"
  26. #include "String.hpp"
  27. /********************************************************************/
  28. /* */
  29. /* Static member initialization. */
  30. /* */
  31. /* Static member initialization sets the initial value for all */
  32. /* static members. */
  33. /* */
  34. /********************************************************************/
  35. #pragma init_seg(lib)
  36. #ifdef DISABLE_STRING_LOCKS
  37. UNIQUE<NO_LOCK> *STRING::Unique;
  38. #else
  39. SPINLOCK STRING::Spinlock;
  40. UNIQUE<FULL_LOCK> *STRING::Unique = NULL;
  41. #endif
  42. /********************************************************************/
  43. /* */
  44. /* Create the string table. */
  45. /* */
  46. /* We create the string table on first use. This is tricky as */
  47. /* we may have created multiple threads so we must be careful */
  48. /* to avoid race conditions. We also arrang for the string table */
  49. /* to be deleted at the end of the run unit. */
  50. /* */
  51. /********************************************************************/
  52. VOID STRING::CreateStringTable( VOID )
  53. {
  54. #ifdef DISABLE_STRING_LOCKS
  55. STATIC DELAY<UNIQUE<NO_LOCK>> Delay;
  56. //
  57. // Create the new string table.
  58. //
  59. Unique = new UNIQUE<NO_LOCK>;
  60. //
  61. // Register the string table for deletion at
  62. // at the end of the run unit.
  63. //
  64. Delay.DeferedDelete( Unique );
  65. #else
  66. //
  67. // Claim a lock to avoid race conditions.
  68. //
  69. Spinlock.ClaimLock();
  70. //
  71. // If the string table still does not exist
  72. // then create it.
  73. //
  74. if ( Unique == NULL )
  75. {
  76. STATIC DELAY< UNIQUE<FULL_LOCK> > Delay;
  77. //
  78. // Create the new string table.
  79. //
  80. Unique = new UNIQUE<FULL_LOCK>;
  81. //
  82. // Register the string table for deletion at
  83. // at the end of the run unit.
  84. //
  85. Delay.DeferedDelete( Unique );
  86. }
  87. //
  88. // Release the lock.
  89. //
  90. Spinlock.ReleaseLock();
  91. #endif
  92. }