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.

162 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. worker.c
  5. Abstract:
  6. work items management functions
  7. Author:
  8. Stefan Solomon 07/11/1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /*++
  14. Function: CreateWorkItemsManager
  15. Descr: creates the work items heap
  16. --*/
  17. HANDLE WiHeapHandle;
  18. ULONG WorkItemsCount;
  19. DWORD
  20. CreateWorkItemsManager(VOID)
  21. {
  22. if((WiHeapHandle = HeapCreate(0,
  23. 0x8000, // 32k initial size
  24. 0x800000 // 8 meg max size
  25. )) == NULL) {
  26. return ERROR_CAN_NOT_COMPLETE;
  27. }
  28. return NO_ERROR;
  29. }
  30. VOID
  31. DestroyWorkItemsManager(VOID)
  32. {
  33. HeapDestroy(WiHeapHandle);
  34. }
  35. /*++
  36. Function: AllocateWorkItem
  37. Descr: allocates the work item from the workitems heap
  38. The function looks at the work item type and allocates a
  39. packet at the end if required
  40. --*/
  41. PWORK_ITEM
  42. AllocateWorkItem(ULONG Type)
  43. {
  44. PWORK_ITEM wip;
  45. switch(Type) {
  46. case UPDATE_STATUS_CHECK_TYPE:
  47. case START_CHANGES_BCAST_TYPE:
  48. case SHUTDOWN_INTERFACES_TYPE:
  49. case PERIODIC_GEN_REQUEST_TYPE:
  50. case DEBUG_TYPE:
  51. if((wip = GlobalAlloc(GPTR, sizeof(WORK_ITEM))) == NULL) {
  52. return NULL;
  53. }
  54. break;
  55. default:
  56. if((wip = HeapAlloc(WiHeapHandle,
  57. HEAP_ZERO_MEMORY,
  58. sizeof(WORK_ITEM) + MAX_PACKET_LEN)) == NULL) {
  59. return NULL;
  60. }
  61. }
  62. wip->Type = Type;
  63. InterlockedIncrement(&WorkItemsCount);
  64. return wip;
  65. }
  66. /*++
  67. Function: FreeWorkItem
  68. Descr: frees the work item to the workitems heap
  69. --*/
  70. VOID
  71. FreeWorkItem(PWORK_ITEM wip)
  72. {
  73. HGLOBAL rc_global;
  74. BOOL rc_heap;
  75. switch(wip->Type) {
  76. case UPDATE_STATUS_CHECK_TYPE:
  77. case START_CHANGES_BCAST_TYPE:
  78. case SHUTDOWN_INTERFACES_TYPE:
  79. case PERIODIC_GEN_REQUEST_TYPE:
  80. case DEBUG_TYPE:
  81. rc_global = GlobalFree(wip);
  82. SS_ASSERT(rc_global == NULL);
  83. break;
  84. default:
  85. rc_heap = HeapFree(WiHeapHandle,
  86. 0,
  87. wip);
  88. SS_ASSERT(rc_heap);
  89. break;
  90. }
  91. InterlockedDecrement(&WorkItemsCount);
  92. }
  93. /*++
  94. Function: EnqueueWorkItemToWorker
  95. Descr: inserts a work item in the workers queue and signals the
  96. semaphore
  97. Remark: Called with the Queues Lock held
  98. --*/
  99. /* Converted to macro
  100. VOID
  101. EnqueueWorkItemToWorker(PWORK_ITEM wip)
  102. {
  103. InsertTailList(&WorkersQueue, &wip->Linkage);
  104. SetEvent(WorkerThreadObjects[WORKERS_QUEUE_EVENT]);
  105. }
  106. */