|
|
@ -45,6 +45,7 @@ struct thd_arg { |
|
|
|
void* arg; /* argument to a thread */ |
|
|
|
void* arg; /* argument to a thread */ |
|
|
|
const char* name; /* name of thread. Can be nullptr. */ |
|
|
|
const char* name; /* name of thread. Can be nullptr. */ |
|
|
|
bool joinable; |
|
|
|
bool joinable; |
|
|
|
|
|
|
|
bool tracked; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class ThreadInternalsPosix : public internal::ThreadInternalsInterface { |
|
|
|
class ThreadInternalsPosix : public internal::ThreadInternalsInterface { |
|
|
@ -64,7 +65,10 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface { |
|
|
|
info->arg = arg; |
|
|
|
info->arg = arg; |
|
|
|
info->name = thd_name; |
|
|
|
info->name = thd_name; |
|
|
|
info->joinable = options.joinable(); |
|
|
|
info->joinable = options.joinable(); |
|
|
|
|
|
|
|
info->tracked = options.tracked(); |
|
|
|
|
|
|
|
if (options.tracked()) { |
|
|
|
Fork::IncThreadCount(); |
|
|
|
Fork::IncThreadCount(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GPR_ASSERT(pthread_attr_init(&attr) == 0); |
|
|
|
GPR_ASSERT(pthread_attr_init(&attr) == 0); |
|
|
|
if (options.joinable()) { |
|
|
|
if (options.joinable()) { |
|
|
@ -108,7 +112,9 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(*arg.body)(arg.arg); |
|
|
|
(*arg.body)(arg.arg); |
|
|
|
|
|
|
|
if (arg.tracked) { |
|
|
|
Fork::DecThreadCount(); |
|
|
|
Fork::DecThreadCount(); |
|
|
|
|
|
|
|
} |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
}, |
|
|
|
}, |
|
|
|
info) == 0); |
|
|
|
info) == 0); |
|
|
@ -118,9 +124,11 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface { |
|
|
|
if (!(*success)) { |
|
|
|
if (!(*success)) { |
|
|
|
/* don't use gpr_free, as this was allocated using malloc (see above) */ |
|
|
|
/* don't use gpr_free, as this was allocated using malloc (see above) */ |
|
|
|
free(info); |
|
|
|
free(info); |
|
|
|
|
|
|
|
if (options.tracked()) { |
|
|
|
Fork::DecThreadCount(); |
|
|
|
Fork::DecThreadCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~ThreadInternalsPosix() override { |
|
|
|
~ThreadInternalsPosix() override { |
|
|
|
gpr_mu_destroy(&mu_); |
|
|
|
gpr_mu_destroy(&mu_); |
|
|
|