RBOOL
    rRwLock_write_lock
    (
        rRwLock lock
    )
{
    RBOOL isSuccess = FALSE;
    _rRwLock* lck = (_rRwLock*)lock;
    RBOOL isReady = FALSE;

    if( rpal_memory_isValid( lock ) )
    {
        while( !isReady )
        {
            if( rMutex_lock( lck->stateLock ) )
            {
                if( 0 == lck->readCount )
                {
                    isReady = TRUE;
                    rEvent_unset( lck->evtCanWrite );
                }
                else
                {
                    rEvent_unset( lck->evtCanRead );
                    rMutex_unlock( lck->stateLock );
                }

                isSuccess = TRUE;
            }

            if( !isReady )
            {
                rEvent_wait( lck->evtCanWrite, RINFINITE );
            }
        }
    }

    return isSuccess;
}
Example #2
0
static RBOOL
    startCollectors
    (

    )
{
    RBOOL isSuccess = FALSE;
    RU32 i = 0;

    rEvent_unset( g_hbs_state.isTimeToStop );
    if( NULL != ( g_hbs_state.hThreadPool = rThreadPool_create( 1, 
                                                                15,
                                                                MSEC_FROM_SEC( 10 ) ) ) )
    {
        isSuccess = TRUE;

        for( i = 0; i < ARRAY_N_ELEM( g_collectors ); i++ )
        {
            if( g_collectors[ i ].isEnabled )
            {
                if( !g_collectors[ i ].init( &g_hbs_state, g_collectors[ i ].conf ) )
                {
                    isSuccess = FALSE;
                    rpal_debug_warning( "collector %d failed to init.", i );
                }
                else
                {
                    rpal_debug_info( "collector %d started.", i );
                }
            }
            else
            {
                rpal_debug_info( "collector %d disabled.", i );
            }
        }
    }

    return isSuccess;
}