1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #pragma once
- #include <windows.h>
- #include <bfc/platform/types.h>
- #include <vector>
- #include "../autolock.h"
- #include "ThreadID.h"
- #include "ThreadFunctions.h"
- #include "threadpool_types.h"
- class ThreadPool : public api_threadpool
- {
- public:
- static const char *getServiceName() { return "Thread Pool API"; }
- static const GUID getServiceGuid() { return ThreadPoolGUID; }
- public:
-
- ThreadPool();
- void Kill();
-
-
- ThreadID *ReserveThread(int flags);
-
- void ReleaseThread(ThreadID *thread_id);
-
- int AddHandle(ThreadID *threadid, HANDLE handle, api_threadpool::ThreadPoolFunc func, void *user_data, intptr_t id, int flags);
- void RemoveHandle(ThreadID *threadid, HANDLE handle);
- int RunFunction(ThreadID *threadid, api_threadpool::ThreadPoolFunc func, void *user_data, intptr_t id, int flags);
- size_t GetNumberOfThreads();
- size_t GetNumberOfActiveThreads();
- private:
- enum
- {
- TYPE_MT = 0,
- TYPE_STA = 1,
- TYPE_MT_RESERVED = 2,
- TYPE_STA_RESERVED = 3,
- THREAD_TYPES = 4,
- };
- private:
- static DWORD CALLBACK WatchDogThreadProcedure_stub(LPVOID param);
- ThreadID *CreateNewThread_Internal(int thread_type = 0);
- DWORD CALLBACK WatchDogThreadProcedure();
- static int GetThreadType(int flags, int reserved = 0);
- static void GetThreadTypes(int flags, bool types[THREAD_TYPES]);
- void RemoveHandle_Internal(size_t start, HANDLE handle);
- void AddHandle_Internal(size_t start, HANDLE handle, int flags);
- Nullsoft::Utility::LockGuard guard;
- typedef std::vector<ThreadID*> ThreadList;
- ThreadList threads;
- ThreadPoolTypes::HandleList any_thread_handles[THREAD_TYPES];
- HANDLE killswitch;
- HANDLE watchdog_thread_handle;
- volatile LONG num_threads_available[THREAD_TYPES];
- ThreadFunctions thread_functions;
- HANDLE max_load_event[THREAD_TYPES];
- protected:
- RECVS_DISPATCH;
- };
|