3 // Copyright (C) 2015-2019 Free Software Foundation, Inc.
5 // This is a reimplementation of libstdc++-v3/src/c++11/futex.cc.
7 #include <bits/atomic_futex.h>
8 #ifdef _GLIBCXX_HAS_GTHREADS
9 #if defined(_GLIBCXX_HAVE_LINUX_FUTEX) && ATOMIC_INT_LOCK_FREE > 1
16 #include <debug/debug.h>
19 #include "execution.h"
21 #include <condition_variable>
23 // Constants for the wait/wake futex syscall operations
24 const unsigned futex_wait_op = 0;
25 const unsigned futex_wake_op = 1;
27 namespace std _GLIBCXX_VISIBILITY(default)
29 _GLIBCXX_BEGIN_NAMESPACE_VERSION
32 __atomic_futex_unsigned_base::_M_futex_wait_until(unsigned *__addr,
34 bool __has_timeout, chrono::seconds __s, chrono::nanoseconds __ns)
36 // do nothing if the two values are not equal
37 if ( *__addr != __val ) {
41 // if a timeout is specified, return immedialy. Letting the scheduler decide how long this thread will wait.
46 ModelExecution *execution = model->get_execution();
48 cdsc::snapcondition_variable *v = new cdsc::snapcondition_variable();
49 cdsc::snapmutex *m = new cdsc::snapmutex();
51 execution->getCondMap()->put( (pthread_cond_t *) __addr, v);
52 execution->getMutexMap()->put( (pthread_mutex_t *) __addr, m);
59 __atomic_futex_unsigned_base::_M_futex_notify_all(unsigned* __addr)
61 // INT_MAX wakes all the waiters at the address __addr
62 ModelExecution *execution = model->get_execution();
63 cdsc::condition_variable *v = execution->getCondMap()->get( (pthread_cond_t *) __addr);
67 _GLIBCXX_END_NAMESPACE_VERSION
69 #endif // defined(_GLIBCXX_HAVE_LINUX_FUTEX) && ATOMIC_INT_LOCK_FREE > 1
70 #endif // _GLIBCXX_HAS_GTHREADS