Futex.h#
Fully qualified name: carb/thread/Futex.h
File members: carb/thread/Futex.h
// SPDX-FileCopyrightText: Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.
#pragma once
#include "detail/FutexImpl.h"
#include <atomic>
namespace carb
{
namespace thread
{
struct futex
{
template <class T>
inline static void wait(const std::atomic<T>& val, T compare) noexcept
{
detail::Futex<T>::wait(val, compare);
}
template <class T, class Rep, class Period>
inline static bool wait_for(const std::atomic<T>& val, T compare, std::chrono::duration<Rep, Period> duration)
{
return detail::Futex<T>::wait_for(val, compare, duration);
}
template <class T, class Clock, class Duration>
inline static bool wait_until(const std::atomic<T>& val, T compare, std::chrono::time_point<Clock, Duration> time_point)
{
return detail::Futex<T>::wait_until(val, compare, time_point);
}
template <class T>
inline static void notify(std::atomic<T>& val, unsigned count, unsigned maxCount = unsigned(INT_MAX)) noexcept
{
if (count != 1 && count >= maxCount)
detail::Futex<T>::notify_all(val);
else
detail::Futex<T>::notify_n(val, count);
}
template <class T>
inline static void notify_n(std::atomic<T>& val, unsigned count) noexcept
{
detail::Futex<T>::notify_n(val, count);
}
template <class T>
CARB_DEPRECATED("use notify() instead")
inline static void wake(std::atomic<T>& val, unsigned count, unsigned maxCount = unsigned(INT_MAX)) noexcept
{
notify(val, count, maxCount);
}
template <class T>
inline static void notify_one(std::atomic<T>& val) noexcept
{
detail::Futex<T>::notify_one(val);
}
template <class T>
CARB_DEPRECATED("use notify_one() instead")
inline static void wake_one(std::atomic<T>& val) noexcept
{
notify_one(val);
}
template <class T>
inline static void notify_all(std::atomic<T>& val) noexcept
{
detail::Futex<T>::notify_all(val);
}
template <class T>
CARB_DEPRECATED("Use notify_all() instead")
inline static void wake_all(std::atomic<T>& val) noexcept
{
notify_all(val);
}
}; // struct futex
} // namespace thread
} // namespace carb