示例#1
0
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;
}
示例#2
0
    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());
    }
示例#3
0
bool SpinMutex::poll()
{
	if (compareAndExchange(&m_id, 1, 0))
	{
		memoryBarrier();
		return true;
	}
	return false;
}
示例#4
0
    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> ();
    }
示例#5
0
void SpinMutex::lock()
{
	for (;;)
	{
		if (compareAndExchange(&m_id, 1, 0))
		{
			memoryBarrier();
			return;
		}

		while (m_id)
		{
			yield();
		}
	}
}
示例#6
0
void SpinMutex::unlock()
{
	memoryBarrier();
	m_id = 0;
}