Exemplo n.º 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 );
        }
    }
Exemplo n.º 2
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;
}