xref: /llvm-project/libc/src/threads/linux/cnd_wait.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
12f4f452fSSiva Chandra Reddy //===-- Linux implementation of the cnd_wait function ---------------------===//
22f4f452fSSiva Chandra Reddy //
32f4f452fSSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42f4f452fSSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
52f4f452fSSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62f4f452fSSiva Chandra Reddy //
72f4f452fSSiva Chandra Reddy //===----------------------------------------------------------------------===//
82f4f452fSSiva Chandra Reddy 
9a5ee8183SSiva Chandra Reddy #include "src/threads/cnd_wait.h"
105442e15aSNick Desaulniers (paternity leave) #include "src/__support/common.h"
11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
125442e15aSNick Desaulniers (paternity leave) #include "src/__support/threads/CndVar.h"
135442e15aSNick Desaulniers (paternity leave) #include "src/__support/threads/mutex.h"
145442e15aSNick Desaulniers (paternity leave) 
155442e15aSNick Desaulniers (paternity leave) #include <threads.h> // cnd_t, mtx_t, thrd_error, thrd_success
162f4f452fSSiva Chandra Reddy 
17*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
182f4f452fSSiva Chandra Reddy 
195442e15aSNick Desaulniers (paternity leave) static_assert(sizeof(CndVar) == sizeof(cnd_t));
205442e15aSNick Desaulniers (paternity leave) 
218379fc4aSSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, cnd_wait, (cnd_t * cond, mtx_t *mtx)) {
228379fc4aSSiva Chandra Reddy   CndVar *cndvar = reinterpret_cast<CndVar *>(cond);
238379fc4aSSiva Chandra Reddy   Mutex *mutex = reinterpret_cast<Mutex *>(mtx);
245442e15aSNick Desaulniers (paternity leave)   return cndvar->wait(mutex) ? thrd_error : thrd_success;
252f4f452fSSiva Chandra Reddy }
262f4f452fSSiva Chandra Reddy 
27*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
28