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.

165 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. tsres.hxx
  5. Abstract:
  6. Defines a wrapper class for locks ( for TCP Services Resources)
  7. used for light-weight syncronization and portability to Win95.
  8. Author:
  9. John Ludeman ( JohnL) 21-Nov-1994
  10. Project:
  11. TCP Services Common DLL
  12. Revision History:
  13. --*/
  14. # ifndef _TSRES_HXX_
  15. # define _TSRES_HXX_
  16. /************************************************************
  17. * Include Headers
  18. ************************************************************/
  19. # ifdef __cplusplus
  20. extern "C" {
  21. # endif // __cplusplus
  22. # include <nt.h>
  23. # include <ntrtl.h>
  24. # ifdef __cplusplus
  25. }; // extern "C"
  26. # endif // __cplusplus
  27. #include <pudebug.h>
  28. #include <irtlmisc.h>
  29. # ifndef TCP_REQUIRE
  30. #define TCP_REQUIRE(x) DBG_REQUIRE(x)
  31. # endif // TCP_REQUIRE
  32. # ifndef TCP_ASSERT
  33. #define TCP_ASSERT(x) DBG_ASSERT(x)
  34. # endif // TCP_REQUIRE
  35. /************************************************************
  36. * Type Definitions
  37. ************************************************************/
  38. # ifdef __cplusplus
  39. extern "C" {
  40. # endif // __cplusplus
  41. BOOL
  42. InetInitializeResource(
  43. IN PRTL_RESOURCE Resource
  44. );
  45. BOOL
  46. InetAcquireResourceShared(
  47. IN PRTL_RESOURCE Resource,
  48. IN BOOL Wait
  49. );
  50. BOOL
  51. InetAcquireResourceExclusive(
  52. IN PRTL_RESOURCE Resource,
  53. IN BOOL Wait
  54. );
  55. BOOL
  56. InetReleaseResource(
  57. IN PRTL_RESOURCE Resource
  58. );
  59. BOOL
  60. InetConvertSharedToExclusive(
  61. IN PRTL_RESOURCE Resource
  62. );
  63. BOOL
  64. InetConvertExclusiveToShared(
  65. IN PRTL_RESOURCE Resource
  66. );
  67. VOID
  68. InetDeleteResource (
  69. IN PRTL_RESOURCE Resource
  70. );
  71. VOID
  72. InetDumpResource(
  73. IN PRTL_RESOURCE Resource
  74. );
  75. # ifdef __cplusplus
  76. }; // extern "C"
  77. # endif // __cplusplus
  78. ///////////////////////////////////////////////////////////////////////
  79. //
  80. // Simple RTL_RESOURCE Wrapper class
  81. //
  82. //////////////////////////////////////////////////////////////////////
  83. enum TSRES_LOCK_TYPE
  84. {
  85. TSRES_LOCK_READ = 0, // Take the lock for read only
  86. TSRES_LOCK_WRITE // Take the lock for write
  87. };
  88. enum TSRES_CONV_TYPE
  89. {
  90. TSRES_CONV_READ = 0, // Convert the lock from write to read
  91. TSRES_CONV_WRITE // Convert the lock from read to write
  92. };
  93. class IRTL_DLLEXP TS_RESOURCE
  94. {
  95. public:
  96. TS_RESOURCE()
  97. { DBG_REQUIRE( InetInitializeResource( &_rtlres )); }
  98. ~TS_RESOURCE()
  99. { InetDeleteResource( &_rtlres ); }
  100. void Lock( enum TSRES_LOCK_TYPE type )
  101. { if ( type == TSRES_LOCK_READ ) {
  102. DBG_REQUIRE( InetAcquireResourceShared( &_rtlres, TRUE ) );
  103. } else {
  104. DBG_REQUIRE( InetAcquireResourceExclusive( &_rtlres, TRUE ));
  105. }
  106. }
  107. void Convert( enum TSRES_CONV_TYPE type )
  108. { if ( type == TSRES_CONV_READ ) {
  109. DBG_REQUIRE( InetConvertExclusiveToShared( &_rtlres ));
  110. } else {
  111. DBG_REQUIRE( InetConvertSharedToExclusive( &_rtlres ));
  112. }
  113. }
  114. void Unlock( VOID )
  115. { DBG_REQUIRE( InetReleaseResource( &_rtlres )); }
  116. private:
  117. RTL_RESOURCE _rtlres;
  118. };
  119. # endif // _TSRES_HXX_
  120. /************************ End of File ***********************/