ThreadID.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <windows.h>
  3. #include "ThreadFunctions.h"
  4. #include "threadpool_types.h"
  5. #include <vector>
  6. class ThreadID : private ThreadFunctions
  7. {
  8. public:
  9. static DWORD CALLBACK thread_func_stub(LPVOID param);
  10. ThreadID(ThreadFunctions *t_f, HANDLE killswitch, HANDLE global_functions_semaphore, ThreadPoolTypes::HandleList &inherited_handles, volatile LONG *thread_count, HANDLE _max_load_event, int _reserved, int _com_type);
  11. ~ThreadID();
  12. void Kill();
  13. /* Try and Wait must be paired!!! */
  14. bool TryAddHandle(HANDLE new_handle);
  15. void WaitAddHandle(HANDLE new_handle);
  16. void AddHandle(HANDLE new_handle);
  17. /* Try and Wait must be paired!!! */
  18. bool TryRemoveHandle(HANDLE handle);
  19. void WaitRemoveHandle(HANDLE handle);
  20. void RemoveHandle(HANDLE handle);
  21. using ThreadFunctions::QueueFunction;
  22. bool IsReserved() const;
  23. bool IsReleased() const;
  24. bool CanRunCOM(int flags) const;
  25. void Reserve(); // re-reserves a released thread
  26. void Release(); // release a reversed thread
  27. private:
  28. void RemoveHandle_Internal(HANDLE handle);
  29. DWORD CALLBACK ThreadFunction();
  30. int reserved;
  31. ThreadFunctions *global_functions;
  32. volatile LONG *num_threads_available;
  33. int com_type;
  34. bool released;
  35. ThreadFunctions local_functions;
  36. // list of handles we're waiting on
  37. typedef std::vector<HANDLE> HandleList;
  38. HandleList wait_handles;
  39. CRITICAL_SECTION handle_lock;
  40. // handles we create/own
  41. HANDLE threadHandle;
  42. HANDLE wakeHandle;
  43. // handles given to us
  44. HANDLE max_load_event;
  45. };