Implement cached thread pool

This commit is contained in:
topjohnwu
2021-08-24 02:39:54 -07:00
parent b591af7803
commit 0cd99712fa
7 changed files with 90 additions and 23 deletions

View File

@@ -121,24 +121,6 @@ int new_daemon_thread(thread_entry entry, void *arg) {
return xpthread_create(&thread, &attr, entry, arg);
}
int new_daemon_thread(void(*entry)()) {
thread_entry proxy = [](void *entry) -> void * {
reinterpret_cast<void(*)()>(entry)();
return nullptr;
};
return new_daemon_thread(proxy, (void *) entry);
}
int new_daemon_thread(std::function<void()> &&entry) {
thread_entry proxy = [](void *fp) -> void * {
auto fn = reinterpret_cast<std::function<void()>*>(fp);
(*fn)();
delete fn;
return nullptr;
};
return new_daemon_thread(proxy, new std::function<void()>(std::move(entry)));
}
static char *argv0;
static size_t name_len;
void init_argv0(int argc, char **argv) {

View File

@@ -82,8 +82,6 @@ static inline int parse_int(std::string_view s) { return parse_int(s.data()); }
using thread_entry = void *(*)(void *);
int new_daemon_thread(thread_entry entry, void *arg = nullptr);
int new_daemon_thread(void(*entry)());
int new_daemon_thread(std::function<void()> &&entry);
static inline bool str_contains(std::string_view s, std::string_view ss) {
return s.find(ss) != std::string::npos;