[libc-commits] [libc] [libc] add `pthread_cond_*` public interfaces (PR #193656)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Thu Apr 23 08:07:02 PDT 2026
================
@@ -0,0 +1,93 @@
+//===-- Shared pthread condition variable helpers ---------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_COND_UTILS_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_COND_UTILS_H
+
+#include "hdr/errno_macros.h" // EINVAL, ETIMEDOUT
+#include "hdr/time_macros.h" // CLOCK_MONOTONIC, CLOCK_REALTIME
+#include "include/llvm-libc-types/clockid_t.h"
+#include "include/llvm-libc-types/pthread_cond_t.h"
+#include "include/llvm-libc-types/pthread_mutex_t.h"
+#include "include/llvm-libc-types/struct_timespec.h"
+#include "src/__support/CPP/optional.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/threads/CndVar.h"
+#include "src/__support/threads/mutex.h"
+#include "src/__support/time/abs_timeout.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace pthread_cond_utils {
+
+static_assert(
+ sizeof(CndVar) == sizeof(pthread_cond_t) &&
+ alignof(CndVar) == alignof(pthread_cond_t),
+ "The public pthread_cond_t type must be of the same size and alignment "
+ "as the internal condition variable type.");
+
+LIBC_INLINE CndVar *to_cndvar(pthread_cond_t *cond) {
+ LIBC_CRASH_ON_NULLPTR(cond);
+ // TODO: use cpp:start_lifetime_as once
----------------
SchrodingerZhu wrote:
Yes, but it is more like a common UB that already exist in codebase.
https://github.com/llvm/llvm-project/pull/193656
More information about the libc-commits
mailing list