mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Join Win32Threads on destruct, like std::jthread
This commit is contained in:
@@ -42,7 +42,7 @@ Win32Thread& Win32Thread::operator=(Win32Thread&& o) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Thread::wait() {
|
Win32Thread::~Win32Thread() {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
WaitForSingleObject(handle.get(), INFINITE);
|
WaitForSingleObject(handle.get(), INFINITE);
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-11
@@ -132,11 +132,15 @@ win32_thread_trampoline(fu2::unique_function<void()>* entry_point);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple RAII wrapper around the Win32 thread API that imitates
|
* A simple RAII wrapper around the Win32 thread API that imitates
|
||||||
* `std::thread`.
|
* `std::jthread`, including implicit joining (or waiting, since this is Win32)
|
||||||
|
* on destruction.
|
||||||
*
|
*
|
||||||
* `std::thread` directly uses pthreads. This means that, like with
|
* `std::thread` uses pthreads directly in Winelib (since this is technically a
|
||||||
* `CreateThread()`, some thread local information does not get initialized
|
* regular Linux application). This means that when using
|
||||||
* which can lead to memory errors.
|
* `std::thread`/`std::jthread` directly, some thread local information that
|
||||||
|
* `CreateThread()` would normally set does not get initialized. This could then
|
||||||
|
* lead to memory errors. This wrapper aims to be equivalent to `std::jthread`,
|
||||||
|
* but using the Win32 API instead.
|
||||||
*
|
*
|
||||||
* @note This should be used instead of `std::thread` or `std::jthread` whenever
|
* @note This should be used instead of `std::thread` or `std::jthread` whenever
|
||||||
* the thread directly calls third party library code, i.e. `LoadLibrary()`,
|
* the thread directly calls third party library code, i.e. `LoadLibrary()`,
|
||||||
@@ -152,7 +156,7 @@ class Win32Thread {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that immediately starts running the thread. This works
|
* Constructor that immediately starts running the thread. This works
|
||||||
* equivalently to `std::thread`.
|
* equivalently to `std::jthread`.
|
||||||
*
|
*
|
||||||
* @param entry_point The thread entry point that should be run.
|
* @param entry_point The thread entry point that should be run.
|
||||||
* @param parameter The parameter passed to the entry point function.
|
* @param parameter The parameter passed to the entry point function.
|
||||||
@@ -178,18 +182,18 @@ class Win32Thread {
|
|||||||
nullptr),
|
nullptr),
|
||||||
CloseHandle) {}
|
CloseHandle) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join (or wait on, since this is WIn32) the thread on shutdown, just like
|
||||||
|
* `std::jthread` does.
|
||||||
|
*/
|
||||||
|
~Win32Thread();
|
||||||
|
|
||||||
Win32Thread(const Win32Thread&) = delete;
|
Win32Thread(const Win32Thread&) = delete;
|
||||||
Win32Thread& operator=(const Win32Thread&) = delete;
|
Win32Thread& operator=(const Win32Thread&) = delete;
|
||||||
|
|
||||||
Win32Thread(Win32Thread&&);
|
Win32Thread(Win32Thread&&);
|
||||||
Win32Thread& operator=(Win32Thread&&);
|
Win32Thread& operator=(Win32Thread&&);
|
||||||
|
|
||||||
/**
|
|
||||||
* Threads in Win32 don't join like threads on other platforms, but it may
|
|
||||||
* still be useful to wait for a thread to terminate.
|
|
||||||
*/
|
|
||||||
void wait();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* The handle for the thread that is running, will be a null pointer if this
|
* The handle for the thread that is running, will be a null pointer if this
|
||||||
|
|||||||
Reference in New Issue
Block a user