Example #1
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 );
        }
    }
Example #2
0
    virtual void run() final
    {
        const bool boolIn = true;
        uint8_t* payload = (uint8_t*)42;

        uint32_t request = requestQ_.pop();
        TEST( handler_.getRequestData( request ) == ++payload );
        handler_.serveRequest( request, boolIn );

        const uint32_t uint32In = 0xC0FFEE;
        request = requestQ_.pop();
        TEST( handler_.getRequestData( request ) == ++payload );
        handler_.serveRequest( request, uint32In );

        request = requestQ_.pop();
        TEST( handler_.getRequestData( request ) == ++payload );
        handler_.serveRequest( request );

        request = requestQ_.pop();
        TESTINFO( handler_.getRequestData( request ) == ++payload,
                  (size_t)handler_.getRequestData( request ) << " for " <<
                  request );
        handler_.serveRequest( request );

        request = requestQ_.pop();
        TEST( handler_.getRequestData( request ) == ++payload );
        handler_.serveRequest( request, uuid );

        request = requestQ_.pop();
        TEST( handler_.getRequestData( request ) == ++payload );
        handler_.serveRequest( request );
    }
Example #3
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;
        }
    }
Example #4
0
int main( int, char** )
{
    uint8_t* payload = (uint8_t*)42;
    Thread thread;
    thread.start();

    uint32_t request = handler_.registerRequest( ++payload );
    requestQ_.push( request );
    bool boolOut = false;
    TEST( handler_.waitRequest( request, boolOut ));
    TEST( boolOut == true );

    lunchbox::Request< uint32_t > future =
        handler_.registerRequest< uint32_t >( ++payload );
    requestQ_.push( future.getID( ));

    request = handler_.registerRequest( ++payload );
    requestQ_.push( request );
    TEST( handler_.waitRequest( request ));

    lunchbox::Request< void > voidFuture =
        handler_.registerRequest< void >( ++payload );
    lunchbox::Request< uint128_t > uint128Future =
        handler_.registerRequest< uint128_t >( ++payload );

    requestQ_.push( voidFuture.getID( ));
    requestQ_.push( uint128Future.getID( ));

    TEST( future.wait( ) == 0xC0FFEE );
    TEST( future.wait( ));
    TEST( uint128Future.wait() == uuid );
    TEST( handler_.isRequestServed( voidFuture.getID( )));
    TEST( voidFuture.isReady( ));
    voidFuture.wait( );

    {
        lunchbox::Request< void > waitAtDestructor =
            handler_.registerRequest< void >( ++payload );
        requestQ_.push( waitAtDestructor.getID( ));
    }

    {
        lunchbox::Request< void > wontBeServed =
            handler_.registerRequest< void >( ++payload );
        try
        {
            wontBeServed.wait( 1 );
            lunchbox::abort();
        }
        catch( const lunchbox::FutureTimeout& ) {}

        TEST( handler_.hasPendingRequests( ))
        wontBeServed.unregister();
        TEST( !handler_.hasPendingRequests( ))

        try
        {
            wontBeServed.wait();
            lunchbox::abort();
        }
        catch( const lunchbox::UnregisteredRequest& ) {}
    }

    TEST( thread.join( ));
    return EXIT_SUCCESS;
}