xref: /llvm-project/libc/src/threads/thrd_equal.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
18dc42802SSiva Chandra Reddy //===-- Implementation of the thrd_equal function -------------------------===//
28dc42802SSiva Chandra Reddy //
38dc42802SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
48dc42802SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
58dc42802SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
68dc42802SSiva Chandra Reddy //
78dc42802SSiva Chandra Reddy //===----------------------------------------------------------------------===//
88dc42802SSiva Chandra Reddy 
98dc42802SSiva Chandra Reddy #include "src/threads/thrd_equal.h"
108dc42802SSiva Chandra Reddy #include "src/__support/common.h"
11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
128dc42802SSiva Chandra Reddy #include "src/__support/threads/thread.h"
138dc42802SSiva Chandra Reddy 
148dc42802SSiva Chandra Reddy #include <threads.h> // For thrd_* type definitions.
158dc42802SSiva Chandra Reddy 
16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
178dc42802SSiva Chandra Reddy 
18b6bc9d72SGuillaume Chatelet static_assert(sizeof(thrd_t) == sizeof(LIBC_NAMESPACE::Thread),
198dc42802SSiva Chandra Reddy               "Mismatch between thrd_t and internal Thread.");
208dc42802SSiva Chandra Reddy 
218dc42802SSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, thrd_equal, (thrd_t lhs, thrd_t rhs)) {
228dc42802SSiva Chandra Reddy   auto *lhs_internal = reinterpret_cast<Thread *>(&lhs);
238dc42802SSiva Chandra Reddy   auto *rhs_internal = reinterpret_cast<Thread *>(&rhs);
248dc42802SSiva Chandra Reddy   return *lhs_internal == *rhs_internal;
258dc42802SSiva Chandra Reddy }
268dc42802SSiva Chandra Reddy 
27*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
28