diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nu/threadpool/ThreadID.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/nu/threadpool/ThreadID.h')
-rw-r--r-- | Src/nu/threadpool/ThreadID.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Src/nu/threadpool/ThreadID.h b/Src/nu/threadpool/ThreadID.h new file mode 100644 index 00000000..e5d1e09e --- /dev/null +++ b/Src/nu/threadpool/ThreadID.h @@ -0,0 +1,56 @@ +#pragma once +#include <windows.h> +#include "ThreadFunctions.h" +#include "threadpool_types.h" +#include <vector> + + +class ThreadID : private ThreadFunctions +{ +public: + static DWORD CALLBACK thread_func_stub(LPVOID param); + 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); + ~ThreadID(); + void Kill(); + + /* Try and Wait must be paired!!! */ + bool TryAddHandle(HANDLE new_handle); + void WaitAddHandle(HANDLE new_handle); + void AddHandle(HANDLE new_handle); + + /* Try and Wait must be paired!!! */ + bool TryRemoveHandle(HANDLE handle); + void WaitRemoveHandle(HANDLE handle); + void RemoveHandle(HANDLE handle); + + using ThreadFunctions::QueueFunction; + bool IsReserved() const; + bool IsReleased() const; + bool CanRunCOM(int flags) const; + void Reserve(); // re-reserves a released thread + void Release(); // release a reversed thread +private: + void RemoveHandle_Internal(HANDLE handle); + DWORD CALLBACK ThreadFunction(); + + int reserved; + ThreadFunctions *global_functions; + volatile LONG *num_threads_available; + int com_type; + bool released; + + ThreadFunctions local_functions; + + // list of handles we're waiting on + typedef std::vector<HANDLE> HandleList; + HandleList wait_handles; + CRITICAL_SECTION handle_lock; + + // handles we create/own + HANDLE threadHandle; + HANDLE wakeHandle; + + // handles given to us + HANDLE max_load_event; + +}; |