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.

136 lines
4.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2000
  3. Module Name:
  4. SContext.hxx
  5. Abstract:
  6. Class definitions for the server side context handles.
  7. Author:
  8. Kamen Moutafov [KamenM]
  9. Revision History:
  10. KamenM Sep 2000 Created
  11. --*/
  12. #if _MSC_VER >= 1200
  13. #pragma once
  14. #endif
  15. #ifndef __SCONTEXT_HXX_
  16. #define __SCONTEXT_HXX_
  17. class ServerContextHandle
  18. {
  19. public:
  20. ServerContextHandle (
  21. IN void *CtxGuard
  22. )
  23. {
  24. // leave ContextChain uninitialized for now
  25. UserContext = NULL;
  26. UserRunDown = NULL;
  27. this->CtxGuard = CtxGuard;
  28. RpcpMemorySet(&WireContext, 0, sizeof(WIRE_CONTEXT));
  29. OwnerSID = NULL;
  30. ReferenceCount = 1;
  31. Flags = ContextPendingAlloc;
  32. }
  33. inline void
  34. AddReference (
  35. void
  36. )
  37. {
  38. long LocalRefCount;
  39. ASSERT(ReferenceCount >= 0);
  40. LocalRefCount = InterlockedIncrement(&ReferenceCount);
  41. LogEvent(SU_CTXHANDLE, EV_INC, this, 0, LocalRefCount, 1, 0);
  42. }
  43. inline long
  44. RemoveReference (
  45. void
  46. )
  47. {
  48. long LocalRefCount;
  49. LocalRefCount = InterlockedDecrement(&ReferenceCount);
  50. LogEvent(SU_CTXHANDLE, EV_DEC, this, 0, LocalRefCount, 1, 0);
  51. ASSERT(LocalRefCount >= 0);
  52. return LocalRefCount;
  53. }
  54. LIST_ENTRY ContextChain; // entry for the context chain
  55. void *UserContext; // context for the user
  56. NDR_RUNDOWN UserRunDown; // user routine to call
  57. void *CtxGuard;
  58. WIRE_CONTEXT WireContext;
  59. // a context handle is not locked until it is put into ContextCompletedAlloc
  60. // state and inserted into the collection.
  61. SWMRLock Lock;
  62. PSID OwnerSID;
  63. // Not protected. Use interlocks. There is one lifetime reference,
  64. // and one or more usage reference. Two paths may clear the lifetime
  65. // reference - the rundown and the marshall path. Both have the lock
  66. // and need to check for the deleted flag to avoid the case where both
  67. // take the lifetime reference
  68. // Whenever the lifetime reference is taken away, the object must be
  69. // removed from the collection so that no new code picks it up
  70. long ReferenceCount;
  71. // All contexts in the collection must have the ContextCompletedAlloc
  72. // flag. Since by the time they enter the collection, this flags
  73. // is constant, no synchronization discipline are necessary for this
  74. // flag
  75. static const long ContextPendingAlloc = 0;
  76. static const long ContextCompletedAlloc = 1;
  77. static const long ContextAllocState = 1;
  78. // Set in the rundown and marshall paths. Checked in the
  79. // the marshall path. All those paths
  80. // set it/check it under the protection of the
  81. // collection lock. If this flag is set, the context is already
  82. // removed, and the lifetime reference is taken away - don't remove
  83. // it and don't take the lifetime reference
  84. // The opposite is also true - if the context handle is in the
  85. // collection, this flag must not be set
  86. static const long ContextRemovedFromCollection = 2;
  87. static const long ContextRemovedFromCollectionMask = 2;
  88. // Set in the rundown path. Checked whenever the refcount drops
  89. // to 0. In both cases protected by the collection lock
  90. static const long ContextNeedsRundown = 4;
  91. static const long ContextNeedsRundownMask = 4;
  92. // the first time newly created context is marshalled, this flag
  93. // is raised. The first time it is unmarshalled, it is taken down
  94. // This allows us to figure out which contexts have been created,
  95. // but not returned to the client in case marshalling fails and treat
  96. // them appropriately. Set in the marshalling path. Checked in the
  97. // unmarshall path. In both cases this is done under the protection
  98. // of the lock
  99. static const long ContextNewlyCreated = 8;
  100. static const long ContextNewlyCreatedMask = 8;
  101. // can be ContextDeleted, ContextPendingAlloc/ContextCompletedAlloc,
  102. // ContextNeedsRundown, ContextNewlyCreated
  103. // Protected by the collection lock for all context handles inserted
  104. // in the collection. No protection needed for the others as no
  105. // multithreaded access is possible
  106. unsigned long Flags;
  107. };
  108. #endif // __SCONTEXT_HXX