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.

143 lines
2.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2000
  3. Module Name:
  4. CtxColl.hxx
  5. Abstract:
  6. Class definitions for the context handle collection.
  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 __CTXCOLL_HXX_
  16. #define __CTXCOLL_HXX_
  17. // the collection of context handles. For right now
  18. // a simple double linked list. For the future, we
  19. // have to find something more scalable for large
  20. // number of elements
  21. class ContextCollection
  22. {
  23. private:
  24. LIST_ENTRY ListHead;
  25. MUTEX CollectionMutex;
  26. public:
  27. ContextCollection (
  28. IN OUT RPC_STATUS *RpcStatus
  29. ) : CollectionMutex(RpcStatus,
  30. TRUE, // fPreallocateSemaphore
  31. 0 // dwSpinCount
  32. )
  33. /*++
  34. Routine Description:
  35. C-tor
  36. Arguments:
  37. RpcStatus - Must be RPC_S_OK on input. Returns either RPC_S_OK or RPC_S_OUT_OF_MEMORY.
  38. --*/
  39. {
  40. RpcpInitializeListHead(&ListHead);
  41. }
  42. inline void
  43. Lock (
  44. void
  45. )
  46. {
  47. CollectionMutex.Request();
  48. }
  49. inline void
  50. Unlock (
  51. void
  52. )
  53. {
  54. CollectionMutex.Clear();
  55. }
  56. inline void
  57. Add (
  58. IN ServerContextHandle *NewHandle
  59. )
  60. {
  61. CollectionMutex.VerifyOwned();
  62. RpcpfInsertHeadList(&ListHead, &NewHandle->ContextChain);
  63. }
  64. inline void
  65. Remove (
  66. IN ServerContextHandle *Handle
  67. )
  68. {
  69. CollectionMutex.VerifyOwned();
  70. RpcpfRemoveEntryList(&Handle->ContextChain);
  71. }
  72. inline ServerContextHandle *
  73. GetNext (
  74. IN OUT LIST_ENTRY **CurrentListEntry
  75. )
  76. {
  77. ServerContextHandle *ContextHandle;
  78. CollectionMutex.VerifyOwned();
  79. ASSERT (CurrentListEntry != NULL);
  80. // if we have started with NULL, return the first element
  81. if (*CurrentListEntry == NULL)
  82. {
  83. *CurrentListEntry = ListHead.Flink;
  84. }
  85. // if we have reached the end (or were empty to start with) return NULL
  86. if (*CurrentListEntry == &ListHead)
  87. {
  88. return NULL;
  89. }
  90. ContextHandle = CONTAINING_RECORD(*CurrentListEntry, ServerContextHandle, ContextChain);
  91. *CurrentListEntry = (*CurrentListEntry)->Flink;
  92. return ContextHandle;
  93. }
  94. ServerContextHandle *
  95. Find (
  96. IN WIRE_CONTEXT *WireContext
  97. );
  98. static RPC_STATUS
  99. AllocateContextCollection (
  100. OUT ContextCollection **NewColl
  101. );
  102. };
  103. RPC_STATUS
  104. NDRSContextInitializeCollection (
  105. IN ContextCollection **ContextCollectionPlaceholder
  106. );
  107. #endif // __CTXCOLL_HXX