예제 #1
0
    void run() override
    {
        if( _master )
            setName( "MasterWorker" );
        else
            setName( "SlaveWorker" );

        _registered.waitEQ( true );
        if( _master )
        {
            _barrier = new co::Barrier( _node, _barrierID );
            _mapped = true;
        }
        else
            _mapped.waitEQ( true );

        for( size_t i = 0; i < _numIterations; ++i )
        {
            const co::uint128_t& version = _versions.pop();

            {
                static lunchbox::SpinLock lock;
                lunchbox::ScopedFastWrite mutex( lock );
                _barrier->sync( version );
            }

            TEST( _barrier->isGood());
            _barrier->enter();
        }

        if( _master )
        {
            _done = true;
            _versions.clear();
            _node->releaseObject( _barrier );
            delete _barrier;
        }
    }
예제 #2
0
    void run() override
    {
        setName( "MasterThread" );
        co::Barrier barrier( _node, _server->getNodeID(), _numThreads );
        barrier.setAutoObsolete( _latency + 1 );
        _barrierID = co::ObjectVersion( &barrier );
        _registered = true;
        _versions.setMaxSize( (_latency + 1) * _numThreads );

        _mapped.waitEQ( true );

        while( !_done )
        {
            TEST( barrier.isGood());

            const co::uint128_t& version = barrier.commit();
            for( size_t i = 0; i < _numThreads; ++i )
                _versions.push( version );
        }
    }
예제 #3
0
int main( int argc, char **argv )
{
    co::init( argc, argv );
    co::Global::setObjectBufferSize( 600 );

    lunchbox::RefPtr< Server > server = new Server;
    co::ConnectionDescriptionPtr connDesc =
        new co::ConnectionDescription;

    connDesc->type = co::CONNECTIONTYPE_TCPIP;
    connDesc->setHostname( "localhost" );

    server->addConnectionDescription( connDesc );
    TEST( server->listen( ));

    co::NodePtr serverProxy = new co::Node;
    serverProxy->addConnectionDescription( connDesc );

    connDesc = new co::ConnectionDescription;
    connDesc->type = co::CONNECTIONTYPE_TCPIP;
    connDesc->setHostname( "localhost" );

    co::LocalNodePtr client = new co::LocalNode;
    client->addConnectionDescription( connDesc );
    TEST( client->listen( ));
    TEST( client->connect( serverProxy ));

    {
        co::Nodes nodes;
        nodes.push_back( serverProxy );

        Camera camera;
        camera.setLookAt( lookAtVector );
        TEST( client->registerObject( &camera ));
        camera.push( co::uint128_t(42), co::uint128_t(42), nodes );

        received.waitEQ( true );
        TEST( server->mapObject( server->object, camera.getID( )));
        TEST( camera == static_cast< const Camera& >( *server->object ));

        camera.setUp( upVector );
        TEST( camera != static_cast< const Camera& >( *server->object ));

        server->object->sync( camera.commit( ));
        TEST( camera == static_cast< const Camera& >( *server->object ));

        server->unmapObject( server->object );
        delete server->object;
        server->object = 0;

        client->deregisterObject( &camera );
    }

    TEST( client->disconnect( serverProxy ));
    TEST( client->close( ));
    TEST( server->close( ));

    serverProxy->printHolders( std::cerr );
    TESTINFO( serverProxy->getRefCount() == 1, serverProxy->getRefCount( ));
    TESTINFO( client->getRefCount() == 1, client->getRefCount( ));
    TESTINFO( server->getRefCount() == 1, server->getRefCount( ));

    serverProxy = 0;
    client      = 0;
    server      = 0;

    co::exit();
    return EXIT_SUCCESS;
}