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.

157 lines
2.8 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. INFSCAN
  5. worker.h
  6. Abstract:
  7. Thread/Job management
  8. History:
  9. Created July 2001 - JamieHun
  10. --*/
  11. #ifndef _INFSCAN_WORKER_H_
  12. #define _INFSCAN_WORKER_H_
  13. class WorkerThread {
  14. private:
  15. HANDLE ThreadHandle;
  16. unsigned ThreadId;
  17. static unsigned __stdcall WrapWorker(void * This);
  18. protected:
  19. //
  20. // override for worker function
  21. //
  22. virtual unsigned Worker();
  23. public:
  24. WorkerThread();
  25. virtual ~WorkerThread();
  26. virtual bool Begin();
  27. virtual unsigned Wait();
  28. };
  29. class GlobalScan;
  30. class JobThread : public WorkerThread {
  31. protected:
  32. virtual unsigned Worker();
  33. public:
  34. GlobalScan * pGlobalScan;
  35. JobThread()
  36. {
  37. pGlobalScan = NULL;
  38. }
  39. JobThread(GlobalScan * globalScan) {
  40. pGlobalScan = globalScan;
  41. }
  42. };
  43. typedef list<JobThread> JobThreadList;
  44. //
  45. // JobItem is what classes can override as a task
  46. //
  47. class JobItem {
  48. friend class JobEntry;
  49. protected:
  50. LONG RefCount;
  51. void AddRef() {
  52. InterlockedIncrement(&RefCount);
  53. }
  54. void Release() {
  55. if(InterlockedDecrement(&RefCount) == 0) {
  56. delete this;
  57. }
  58. }
  59. public:
  60. virtual int Run();
  61. virtual int PartialCleanup();
  62. virtual int Results();
  63. virtual int PreResults();
  64. public:
  65. JobItem() {
  66. RefCount = 0;
  67. }
  68. virtual ~JobItem();
  69. };
  70. //
  71. // JobEntry is a container for a JobItem
  72. // note that a JobItem is ref-counted
  73. //
  74. class JobEntry {
  75. private:
  76. JobItem *pItem;
  77. public:
  78. void ChangeItem(JobItem *item) {
  79. if(item) {
  80. item->AddRef();
  81. }
  82. if(pItem) {
  83. pItem->Release();
  84. }
  85. pItem = item;
  86. }
  87. JobEntry(JobItem *item = NULL) {
  88. if(item) {
  89. item->AddRef();
  90. }
  91. pItem = item;
  92. }
  93. JobEntry(const JobEntry & from) {
  94. if(from.pItem) {
  95. const_cast<JobEntry*>(&from)->pItem->AddRef();
  96. }
  97. pItem = from.pItem;
  98. }
  99. ~JobEntry() {
  100. if(pItem) {
  101. pItem->Release();
  102. }
  103. }
  104. int Run() {
  105. if(pItem) {
  106. return pItem->Run();
  107. } else {
  108. return -1;
  109. }
  110. }
  111. int PartialCleanup() {
  112. if(pItem) {
  113. return pItem->PartialCleanup();
  114. } else {
  115. return -1;
  116. }
  117. }
  118. int PreResults() {
  119. if(pItem) {
  120. return pItem->PreResults();
  121. } else {
  122. return -1;
  123. }
  124. }
  125. int Results() {
  126. if(pItem) {
  127. return pItem->Results();
  128. } else {
  129. return -1;
  130. }
  131. }
  132. };
  133. typedef list<JobEntry> JobList;
  134. #endif //!_INFSCAN_WORKER_H_