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.

165 lines
3.2 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. # ifndef TCP_REQUIRE
  29. #define TCP_REQUIRE(x) DBG_REQUIRE(x)
  30. # endif // TCP_REQUIRE
  31. # ifndef TCP_ASSERT
  32. #define TCP_ASSERT(x) DBG_ASSERT(x)
  33. # endif // TCP_REQUIRE
  34. /************************************************************
  35. * Type Definitions
  36. ************************************************************/
  37. # ifdef __cplusplus
  38. extern "C" {
  39. # endif // __cplusplus
  40. BOOL
  41. InetInitializeResource(
  42. IN PRTL_RESOURCE Resource
  43. );
  44. BOOL
  45. InetAcquireResourceShared(
  46. IN PRTL_RESOURCE Resource,
  47. IN BOOL Wait
  48. );
  49. BOOL
  50. InetAcquireResourceExclusive(
  51. IN PRTL_RESOURCE Resource,
  52. IN BOOL Wait
  53. );
  54. BOOL
  55. InetReleaseResource(
  56. IN PRTL_RESOURCE Resource
  57. );
  58. BOOL
  59. InetConvertSharedToExclusive(
  60. IN PRTL_RESOURCE Resource
  61. );
  62. BOOL
  63. InetConvertExclusiveToShared(
  64. IN PRTL_RESOURCE Resource
  65. );
  66. VOID
  67. InetDeleteResource (
  68. IN PRTL_RESOURCE Resource
  69. );
  70. VOID
  71. InetDumpResource(
  72. IN PRTL_RESOURCE Resource
  73. );
  74. # ifdef __cplusplus
  75. }; // extern "C"
  76. # endif // __cplusplus
  77. ///////////////////////////////////////////////////////////////////////
  78. //
  79. // Simple RTL_RESOURCE Wrapper class
  80. //
  81. //////////////////////////////////////////////////////////////////////
  82. enum TSRES_LOCK_TYPE
  83. {
  84. TSRES_LOCK_READ = 0, // Take the lock for read only
  85. TSRES_LOCK_WRITE // Take the lock for write
  86. };
  87. enum TSRES_CONV_TYPE
  88. {
  89. TSRES_CONV_READ = 0, // Convert the lock from write to read
  90. TSRES_CONV_WRITE // Convert the lock from read to write
  91. };
  92. class dllexp TS_RESOURCE
  93. {
  94. public:
  95. TS_RESOURCE()
  96. { DBG_REQUIRE( InetInitializeResource( &_rtlres )); }
  97. ~TS_RESOURCE()
  98. { InetDeleteResource( &_rtlres ); }
  99. void Lock( enum TSRES_LOCK_TYPE type )
  100. { if ( type == TSRES_LOCK_READ ) {
  101. DBG_REQUIRE( InetAcquireResourceShared( &_rtlres, TRUE ) );
  102. } else {
  103. DBG_REQUIRE( InetAcquireResourceExclusive( &_rtlres, TRUE ));
  104. }
  105. }
  106. void Convert( enum TSRES_CONV_TYPE type )
  107. { if ( type == TSRES_CONV_READ ) {
  108. DBG_REQUIRE( InetConvertExclusiveToShared( &_rtlres ));
  109. } else {
  110. DBG_REQUIRE( InetConvertSharedToExclusive( &_rtlres ));
  111. }
  112. }
  113. void Unlock( VOID )
  114. { DBG_REQUIRE( InetReleaseResource( &_rtlres )); }
  115. private:
  116. RTL_RESOURCE _rtlres;
  117. };
  118. # endif // _TSRES_HXX_
  119. /************************ End of File ***********************/