1
0

ThreadFunctions.h 923 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include "api_threadpool.h"
  3. #include <map>
  4. #include <deque>
  5. #include "../AutoLock.h"
  6. class ThreadFunctions
  7. {
  8. public:
  9. struct Data
  10. {
  11. api_threadpool::ThreadPoolFunc func;
  12. void *user_data;
  13. intptr_t id;
  14. };
  15. ThreadFunctions(int create_function_list=1);
  16. ~ThreadFunctions();
  17. void Add(HANDLE handle, api_threadpool::ThreadPoolFunc func, void *user_data, intptr_t id);
  18. bool Get(HANDLE handle, api_threadpool::ThreadPoolFunc *func, void **user_data, intptr_t *id);
  19. void QueueFunction(api_threadpool::ThreadPoolFunc func, void *user_data, intptr_t id);
  20. bool PopFunction(api_threadpool::ThreadPoolFunc *func, void **user_data, intptr_t *id);
  21. typedef std::map<HANDLE, const ThreadFunctions::Data*> DataMap;
  22. DataMap data;
  23. Nullsoft::Utility::LockGuard guard;
  24. typedef std::deque<ThreadFunctions::Data*> FuncList;
  25. FuncList functions_list;
  26. CRITICAL_SECTION functions_guard;
  27. HANDLE functions_semaphore;
  28. };