Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85990 - trunk/boost/sync/detail
From: andrey.semashev_at_[hidden]
Date: 2013-09-28 14:07:51


Author: andysem
Date: 2013-09-28 14:07:51 EDT (Sat, 28 Sep 2013)
New Revision: 85990
URL: http://svn.boost.org/trac/boost/changeset/85990

Log:
Added a header with formal declarations of futex operations.

Added:
   trunk/boost/sync/detail/futex.hpp (contents, props changed)

Added: trunk/boost/sync/detail/futex.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/futex.hpp 2013-09-28 14:07:51 EDT (Sat, 28 Sep 2013) (r85990)
@@ -0,0 +1,119 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * (C) Copyright 2013 Tim Blechmann
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file futex.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ *
+ * This header contains Linux futex API declarations.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_FUTEX_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_FUTEX_HPP_INCLUDED_
+
+#include <stddef.h>
+#include <limits.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/syscall.h>
+#include <linux/futex.h>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+namespace detail {
+
+namespace linux {
+
+//! Invokes an operation on the futex
+BOOST_FORCEINLINE int futex_invoke(int* addr1, int op, int val1, const struct ::timespec* timeout = NULL, int* addr2 = NULL, int val3 = 0) BOOST_NOEXCEPT
+{
+ return ::syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
+}
+
+//! Checks that the value \c pval is \c expected and blocks
+BOOST_FORCEINLINE int futex_wait(int* pval, int expected) BOOST_NOEXCEPT
+{
+ return futex_invoke
+ (
+ pval,
+#ifdef FUTEX_WAIT_PRIVATE
+ FUTEX_WAIT_PRIVATE,
+#else
+ FUTEX_WAIT,
+#endif
+ expected
+ );
+}
+
+//! Checks that the value \c pval is \c expected and blocks until \c timeout
+BOOST_FORCEINLINE int futex_timedwait(int* pval, int expected, const struct ::timespec* timeout) BOOST_NOEXCEPT
+{
+ return futex_invoke
+ (
+ pval,
+#ifdef FUTEX_WAIT_PRIVATE
+ FUTEX_WAIT_PRIVATE,
+#else
+ FUTEX_WAIT,
+#endif
+ expected,
+ timeout
+ );
+}
+
+//! Wakes all threads waiting on the futex
+BOOST_FORCEINLINE int futex_broadcast(int* pval) BOOST_NOEXCEPT
+{
+ return futex_invoke
+ (
+ pval,
+#ifdef FUTEX_WAKE_PRIVATE
+ FUTEX_WAKE_PRIVATE,
+#else
+ FUTEX_WAKE,
+#endif
+ INT_MAX
+ );
+}
+
+//! Wakes one thread waiting on the futex
+BOOST_FORCEINLINE int futex_signal(int* pval) BOOST_NOEXCEPT
+{
+ return futex_invoke
+ (
+ pval,
+#ifdef FUTEX_WAKE_PRIVATE
+ FUTEX_WAKE_PRIVATE,
+#else
+ FUTEX_WAKE,
+#endif
+ 1
+ );
+}
+
+} // namespace linux
+
+} // namespace detail
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_FUTEX_HPP_INCLUDED_


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk