]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/std_mutex.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / std_mutex.h
index 56c853a3fdcefd4fbb7974dbe843169c162f168a..3a394601868bef49e3f353282087edfe429db42b 100644 (file)
@@ -1,6 +1,6 @@
 // std::mutex implementation -*- C++ -*-
 
-// Copyright (C) 2003-2020 Free Software Foundation, Inc.
+// Copyright (C) 2003-2021 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -123,6 +123,76 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { return &_M_mutex; }
   };
 
+  // Implementation details for std::condition_variable
+  class __condvar
+  {
+    using timespec = __gthread_time_t;
+
+  public:
+    __condvar() noexcept
+    {
+#ifndef __GTHREAD_COND_INIT
+      __GTHREAD_COND_INIT_FUNCTION(&_M_cond);
+#endif
+    }
+
+    ~__condvar()
+    {
+      int __e __attribute__((__unused__)) = __gthread_cond_destroy(&_M_cond);
+      __glibcxx_assert(__e != EBUSY); // threads are still blocked
+    }
+
+    __condvar(const __condvar&) = delete;
+    __condvar& operator=(const __condvar&) = delete;
+
+    __gthread_cond_t* native_handle() noexcept { return &_M_cond; }
+
+    // Expects: Calling thread has locked __m.
+    void
+    wait(mutex& __m) noexcept
+    {
+      int __e __attribute__((__unused__))
+       = __gthread_cond_wait(&_M_cond, __m.native_handle());
+      __glibcxx_assert(__e == 0);
+    }
+
+    void
+    wait_until(mutex& __m, timespec& __abs_time) noexcept
+    {
+      __gthread_cond_timedwait(&_M_cond, __m.native_handle(), &__abs_time);
+    }
+
+#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
+    void
+    wait_until(mutex& __m, clockid_t __clock, timespec& __abs_time) noexcept
+    {
+      pthread_cond_clockwait(&_M_cond, __m.native_handle(), __clock,
+                            &__abs_time);
+    }
+#endif
+
+    void
+    notify_one() noexcept
+    {
+      int __e __attribute__((__unused__)) = __gthread_cond_signal(&_M_cond);
+      __glibcxx_assert(__e == 0);
+    }
+
+    void
+    notify_all() noexcept
+    {
+      int __e __attribute__((__unused__)) = __gthread_cond_broadcast(&_M_cond);
+      __glibcxx_assert(__e == 0);
+    }
+
+  protected:
+#ifdef __GTHREAD_COND_INIT
+    __gthread_cond_t _M_cond = __GTHREAD_COND_INIT;
+#else
+    __gthread_cond_t _M_cond;
+#endif
+  };
+
 #endif // _GLIBCXX_HAS_GTHREADS
 
   /// Do not acquire ownership of the mutex.