void Stoppable::stopRecursive (Journal journal) { // Block on each child from the bottom of the tree up. // for (Children::const_iterator iter (m_children.cbegin ()); iter != m_children.cend(); ++iter) iter->stoppable->stopRecursive (journal); // if we get here then all children have stopped // memoryBarrier (); m_childrenStopped = true; onChildrenStopped (); // Now block on this Stoppable. // bool const timedOut (! m_stoppedEvent.wait (1 * 1000)); // milliseconds if (timedOut) { journal.warning << "Waiting for '" << m_name << "' to stop"; m_stoppedEvent.wait (); } // once we get here, we know the stoppable has stopped. m_stopped = true; }
void testFloat () { Atomic<Type> a, b; a = (Type) 21; memoryBarrier(); /* These are some simple test cases to check the atomics - let me know if any of these assertions fail on your system! */ expect (a.get() == (Type) 21); expect (a.compareAndSetValue ((Type) 100, (Type) 50) == (Type) 21); expect (a.get() == (Type) 21); expect (a.compareAndSetValue ((Type) 101, a.get()) == (Type) 21); expect (a.get() == (Type) 101); expect (! a.compareAndSetBool ((Type) 300, (Type) 200)); expect (a.get() == (Type) 101); expect (a.compareAndSetBool ((Type) 200, a.get())); expect (a.get() == (Type) 200); expect (a.exchange ((Type) 300) == (Type) 200); expect (a.get() == (Type) 300); b = a; expect (b.get() == a.get()); }
bool SpinMutex::poll() { if (compareAndExchange(&m_id, 1, 0)) { memoryBarrier(); return true; } return false; }
void testInteger () { Atomic<Type> a, b; a.set ((Type) 10); expect (a.value == (Type) 10); expect (a.get() == (Type) 10); a += (Type) 15; expect (a.get() == (Type) 25); memoryBarrier(); a -= (Type) 5; expect (a.get() == (Type) 20); expect (++a == (Type) 21); ++a; expect (--a == (Type) 21); expect (a.get() == (Type) 21); memoryBarrier(); testFloat <Type> (); }
void SpinMutex::lock() { for (;;) { if (compareAndExchange(&m_id, 1, 0)) { memoryBarrier(); return; } while (m_id) { yield(); } } }
void SpinMutex::unlock() { memoryBarrier(); m_id = 0; }