ppc-lang/include/utils/threading.hh

40 lines
1.0 KiB
C++
Raw Normal View History

2022-09-19 07:34:19 +00:00
#pragma once
#ifdef WINDOWS
#define THREAD __stdcall
#else
#define THREAD
#endif
namespace ppc::threading {
2023-01-26 08:06:39 +00:00
template <class ParserT>
using thread_func_t = int (THREAD *)(ParserT *data);
2022-09-19 07:34:19 +00:00
using empty_thread_func_t = int (THREAD *)();
struct thread_t {
private:
void *handle;
static thread_t start_impl(void *func, void *args);
public:
int join() const;
thread_t(void *handle) { this->handle = handle; }
2023-01-26 08:06:39 +00:00
template <class ParserT>
inline static thread_t start(thread_func_t<ParserT> func, const ParserT &args) {
ParserT _args = args;
2022-09-19 07:34:19 +00:00
return start_impl((void*)func, &_args);
}
2023-01-26 08:06:39 +00:00
template <class ParserT>
inline static thread_t start(thread_func_t<ParserT> func, ParserT &args) {
2022-09-19 07:34:19 +00:00
return start_impl((void*)func, &args);
}
inline static thread_t start(empty_thread_func_t func) {
return start<int>((thread_func_t<int>)func, 0);
}
~thread_t();
};
}