|
|
|
@@ -28,6 +28,7 @@ |
|
|
|
#ifdef _WIN32 |
|
|
|
#define WIN32_LEAN_AND_MEAN |
|
|
|
#include <windows.h> |
|
|
|
#include <process.h> |
|
|
|
#else |
|
|
|
#include <pthread.h> |
|
|
|
#endif |
|
|
|
@@ -96,6 +97,39 @@ private: |
|
|
|
}; |
|
|
|
#endif // _WIN32 |
|
|
|
|
|
|
|
#if _WIN32 |
|
|
|
static unsigned __stdcall start_wrapper(void* args); |
|
|
|
class Thread |
|
|
|
{ |
|
|
|
public: |
|
|
|
Thread(void* (*start)(void*), void* args = 0) { _start = start; _args = args; handle = (HANDLE)_beginthreadex(0, 0, start_wrapper, this, 0, 0); } |
|
|
|
~Thread() {} |
|
|
|
void join() { WaitForSingleObject(handle, INFINITE); CloseHandle(handle); } |
|
|
|
private: |
|
|
|
friend static unsigned __stdcall start_wrapper(void* arg); |
|
|
|
HANDLE handle; |
|
|
|
void* (*_start)(void*); |
|
|
|
void* _args; |
|
|
|
}; |
|
|
|
|
|
|
|
static unsigned __stdcall start_wrapper(void* args) |
|
|
|
{ |
|
|
|
Thread* t = (Thread*)args; |
|
|
|
t->_start(t->_args); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
#else // _WIN32 |
|
|
|
class Thread |
|
|
|
{ |
|
|
|
public: |
|
|
|
Thread(void* (*start)(void*), void* args = 0) { pthread_create(&t, 0, start, args); } |
|
|
|
~Thread() {} |
|
|
|
void join() { pthread_join(t, 0); } |
|
|
|
private: |
|
|
|
pthread_t t; |
|
|
|
}; |
|
|
|
#endif // _WIN32 |
|
|
|
|
|
|
|
} // namespace ncnn |
|
|
|
|
|
|
|
#endif // NCNN_PLATFORM_H |