xref: /llvm-project/libc/src/threads/thrd_join.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
12ce09e68SSiva Chandra Reddy //===-- Linux implementation of the thrd_join function --------------------===//
22ce09e68SSiva Chandra Reddy //
32ce09e68SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42ce09e68SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
52ce09e68SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62ce09e68SSiva Chandra Reddy //
72ce09e68SSiva Chandra Reddy //===----------------------------------------------------------------------===//
82ce09e68SSiva Chandra Reddy 
92ce09e68SSiva Chandra Reddy #include "src/threads/thrd_join.h"
102ce09e68SSiva Chandra Reddy #include "src/__support/common.h"
11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
122ce09e68SSiva Chandra Reddy #include "src/__support/threads/thread.h"
132ce09e68SSiva Chandra Reddy 
142ce09e68SSiva Chandra Reddy #include <threads.h> // For thrd_* type definitions.
152ce09e68SSiva Chandra Reddy 
16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
172ce09e68SSiva Chandra Reddy 
18b6bc9d72SGuillaume Chatelet static_assert(sizeof(thrd_t) == sizeof(LIBC_NAMESPACE::Thread),
19f4580c6dSSiva Chandra Reddy               "Mismatch between thrd_t and internal Thread.");
202ce09e68SSiva Chandra Reddy 
2157afb480SSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, thrd_join, (thrd_t th, int *retval)) {
2257afb480SSiva Chandra Reddy   auto *thread = reinterpret_cast<Thread *>(&th);
23ad89cf4eSSiva Chandra Reddy   int result = thread->join(retval);
24ad89cf4eSSiva Chandra Reddy   return result == 0 ? thrd_success : thrd_error;
252ce09e68SSiva Chandra Reddy }
262ce09e68SSiva Chandra Reddy 
27*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
28