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.

155 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. volatile LONG WorkItemsCount;
  19. DWORD
  20. CreateWorkItemsManager(VOID)
  21. {
  22. if((WiHeapHandle = HeapCreate(0,
  23. 0x8000, // 32k initial size
  24. 0x100000 // 1 meg max size
  25. )) == NULL) {
  26. return ERROR_CAN_NOT_COMPLETE;
  27. }
  28. WorkItemsCount = 0;
  29. return NO_ERROR;
  30. }
  31. VOID
  32. DestroyWorkItemsManager(VOID)
  33. {
  34. while (WorkItemsCount>0)
  35. SleepEx (1000, TRUE);
  36. HeapDestroy(WiHeapHandle);
  37. }
  38. /*++
  39. Function: AllocateWorkItem
  40. Descr: allocates the work item from the workitems heap
  41. The function looks at the work item type and allocates a
  42. packet at the end if required
  43. --*/
  44. PWORK_ITEM
  45. AllocateWorkItem(ULONG Type)
  46. {
  47. PWORK_ITEM wip;
  48. switch(Type) {
  49. case WITIMER_TYPE:
  50. if((wip = GlobalAlloc(GPTR, sizeof(WORK_ITEM))) == NULL) {
  51. return NULL;
  52. }
  53. break;
  54. default:
  55. if((wip = HeapAlloc(WiHeapHandle,
  56. HEAP_ZERO_MEMORY,
  57. sizeof(WORK_ITEM) + MAX_IPXWAN_PACKET_LEN)) == NULL) {
  58. return NULL;
  59. }
  60. }
  61. wip->Type = Type;
  62. InterlockedIncrement((PLONG)&WorkItemsCount);
  63. return wip;
  64. }
  65. /*++
  66. Function: FreeWorkItem
  67. Descr: frees the work item to the workitems heap
  68. --*/
  69. VOID
  70. FreeWorkItem(PWORK_ITEM wip)
  71. {
  72. HGLOBAL rc_global;
  73. BOOL rc_heap;
  74. switch(wip->Type) {
  75. case WITIMER_TYPE:
  76. rc_global = GlobalFree(wip);
  77. SS_ASSERT(rc_global == NULL);
  78. break;
  79. default:
  80. rc_heap = HeapFree(WiHeapHandle,
  81. 0,
  82. wip);
  83. SS_ASSERT(rc_heap);
  84. break;
  85. }
  86. InterlockedDecrement((PLONG)&WorkItemsCount);
  87. }
  88. /*++
  89. Function: EnqueueWorkItemToWorker
  90. Descr: inserts a work item in the workers queue and signals the
  91. event
  92. Remark: Called with the Queues Lock held
  93. --*/
  94. VOID
  95. EnqueueWorkItemToWorker(PWORK_ITEM wip)
  96. {
  97. InsertTailList(&WorkersQueue, &wip->Linkage);
  98. SetEvent(hWaitableObject[WORKERS_QUEUE_EVENT]);
  99. }