forked from OSchip/llvm-project
[libc][NFC] Move thread platform data pointer to thread attributes.
Along the way, added constexpr constructors to the Thread data structures.
This commit is contained in:
parent
9049c46b9d
commit
3c5d6312c4
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *__attrib;
|
void *__attrib;
|
||||||
void *__platform_attrib;
|
|
||||||
} __thread_type;
|
} __thread_type;
|
||||||
|
|
||||||
#endif // __LLVM_LIBC_TYPES_THREAD_TYPE_H__
|
#endif // __LLVM_LIBC_TYPES_THREAD_TYPE_H__
|
||||||
|
|
|
@ -99,7 +99,8 @@ __attribute__((always_inline)) inline uintptr_t get_start_args_addr() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_thread() __attribute__((noinline)) {
|
__attribute__((noinline))
|
||||||
|
static void start_thread() {
|
||||||
auto *start_args = reinterpret_cast<StartArgs *>(get_start_args_addr());
|
auto *start_args = reinterpret_cast<StartArgs *>(get_start_args_addr());
|
||||||
auto *attrib = start_args->thread_attrib;
|
auto *attrib = start_args->thread_attrib;
|
||||||
long retval;
|
long retval;
|
||||||
|
@ -174,7 +175,7 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
|
||||||
auto clear_tid = reinterpret_cast<cpp::Atomic<FutexWordType> *>(
|
auto clear_tid = reinterpret_cast<cpp::Atomic<FutexWordType> *>(
|
||||||
adjusted_stack + sizeof(StartArgs) + sizeof(ThreadAttributes));
|
adjusted_stack + sizeof(StartArgs) + sizeof(ThreadAttributes));
|
||||||
clear_tid->val = CLEAR_TID_VALUE;
|
clear_tid->val = CLEAR_TID_VALUE;
|
||||||
platform_data = clear_tid;
|
attrib->platform_data = clear_tid;
|
||||||
|
|
||||||
// The clone syscall takes arguments in an architecture specific order.
|
// The clone syscall takes arguments in an architecture specific order.
|
||||||
// Also, we want the result of the syscall to be in a register as the child
|
// Also, we want the result of the syscall to be in a register as the child
|
||||||
|
@ -252,7 +253,7 @@ void Thread::wait() {
|
||||||
// If not, it is a spurious wake and we should continue to wait on
|
// If not, it is a spurious wake and we should continue to wait on
|
||||||
// the futex.
|
// the futex.
|
||||||
auto *clear_tid =
|
auto *clear_tid =
|
||||||
reinterpret_cast<cpp::Atomic<FutexWordType> *>(platform_data);
|
reinterpret_cast<cpp::Atomic<FutexWordType> *>(attrib->platform_data);
|
||||||
while (clear_tid->load() != 0) {
|
while (clear_tid->load() != 0) {
|
||||||
// We cannot do a FUTEX_WAIT_PRIVATE here as the kernel does a
|
// We cannot do a FUTEX_WAIT_PRIVATE here as the kernel does a
|
||||||
// FUTEX_WAKE and not a FUTEX_WAKE_PRIVATE.
|
// FUTEX_WAKE and not a FUTEX_WAKE_PRIVATE.
|
||||||
|
|
|
@ -28,6 +28,7 @@ union ThreadRunner {
|
||||||
union ThreadReturnValue {
|
union ThreadReturnValue {
|
||||||
void *posix_retval;
|
void *posix_retval;
|
||||||
int stdc_retval;
|
int stdc_retval;
|
||||||
|
constexpr ThreadReturnValue() : posix_retval(nullptr) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if (defined(LLVM_LIBC_ARCH_AARCH64) || defined(LLVM_LIBC_ARCH_X86_64))
|
#if (defined(LLVM_LIBC_ARCH_AARCH64) || defined(LLVM_LIBC_ARCH_X86_64))
|
||||||
|
@ -87,13 +88,21 @@ struct alignas(STACK_ALIGNMENT) ThreadAttributes {
|
||||||
int tid;
|
int tid;
|
||||||
ThreadStyle style;
|
ThreadStyle style;
|
||||||
ThreadReturnValue retval;
|
ThreadReturnValue retval;
|
||||||
|
void *platform_data;
|
||||||
|
|
||||||
|
constexpr ThreadAttributes()
|
||||||
|
: detach_state(uint32_t(DetachState::DETACHED)), stack(nullptr),
|
||||||
|
tls(nullptr), stack_size(0), owned_stack(false), tid(-1),
|
||||||
|
style(ThreadStyle::POSIX), retval(),
|
||||||
|
platform_data(nullptr) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Thread {
|
struct Thread {
|
||||||
ThreadAttributes *attrib;
|
ThreadAttributes *attrib;
|
||||||
void *platform_data;
|
|
||||||
|
|
||||||
Thread() = default;
|
constexpr Thread() : attrib(nullptr) {}
|
||||||
|
constexpr Thread(ThreadAttributes *attr) : attrib(attr) {}
|
||||||
|
|
||||||
int run(ThreadRunnerPosix *func, void *arg, void *stack, size_t size,
|
int run(ThreadRunnerPosix *func, void *arg, void *stack, size_t size,
|
||||||
bool detached = false) {
|
bool detached = false) {
|
||||||
|
|
Loading…
Reference in New Issue