[libc-commits] [libc] [libc] refactor futex and remove dependency cycle (PR #117923)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Dec 2 10:30:34 PST 2024


================
@@ -0,0 +1,62 @@
+//===--- Futex Wrapper ------------------------------------------*- 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___SUPPORT_THREADS_LINUX_FUTEX_TIMEOUT_H
+#define LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_FUTEX_TIMEOUT_H
+
+#include "src/__support/CPP/atomic.h"
+#include "src/__support/CPP/limits.h"
+#include "src/__support/CPP/optional.h"
+#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/linux/futex_utils.h"
+#include "src/__support/time/linux/abs_timeout.h"
+
+namespace LIBC_NAMESPACE_DECL {
+class TimedFutex : public Futex {
+public:
+  using Timeout = internal::AbsTimeout;
+  using Futex::Futex;
+  using Futex::operator=;
+  LIBC_INLINE long wait(FutexWordType expected,
+                        cpp::optional<Timeout> timeout = cpp::nullopt,
----------------
nickdesaulniers wrote:

So if we make the distinction between `Futex` now not having a timeout, and `TimedFutex` having a timeout, then I think the `timeout` parameter of the `TimedFutex::wait` method should not be optional.

https://github.com/llvm/llvm-project/pull/117923


More information about the libc-commits mailing list