예제 #1
0
int _getAndUseIFuseConn( iFuseConn_t **iFuseConn ) {
    int status;
    iFuseConn_t *tmpIFuseConn;

    *iFuseConn = NULL;

    LOCK( WaitForConnLock );
    while ( listSize( ConnectedConn ) >= MAX_NUM_CONN && listSize( FreeConn ) == 0 ) {
        untimedWait( &connReqWait.mutex, &connReqWait.cond );
    }

    tmpIFuseConn = ( iFuseConn_t * ) removeFirstElementOfConcurrentList( FreeConn );
    if ( tmpIFuseConn == NULL ) {
        if ( listSize( ConnectedConn ) < MAX_NUM_CONN ) {
            tmpIFuseConn = newIFuseConn( &status );
            if ( status < 0 ) {
                _freeIFuseConn( tmpIFuseConn );
                return status;
            }
            _useFreeIFuseConn( tmpIFuseConn );
            addToConcurrentList( ConnectedConn, tmpIFuseConn );
            *iFuseConn = tmpIFuseConn;
        }
        else {
            rodsLog( LOG_ERROR, "failure to acquire fuse connection; maximum fuse connections exceeded." );
            return SYS_MAX_CONNECT_COUNT_EXCEEDED;
        }
    }
    else {
        useIFuseConn( tmpIFuseConn );
        *iFuseConn = tmpIFuseConn;
    }
    UNLOCK( WaitForConnLock );

    if ( ++ConnManagerStarted == HIGH_NUM_CONN ) {
        /* don't do it the first time */

#ifdef USE_BOOST
        ConnManagerThr = new boost::thread( connManager );
#else
        status = pthread_create( &ConnManagerThr, pthread_attr_default, ( void * ( * )( void * ) ) connManager, ( void * ) NULL );
#endif
        if ( status < 0 ) {
            ConnManagerStarted--;
            rodsLog( LOG_ERROR, "pthread_create failure, status = %d", status );
        }
    }
    return 0;
}
예제 #2
0
int _getAndUseIFuseConn( iFuseConn_t **iFuseConn ) {
    int status;
    iFuseConn_t *tmpIFuseConn;

    *iFuseConn = NULL;

    while ( *iFuseConn == NULL ) {
        /* get a free IFuseConn */

        if ( listSize( ConnectedConn ) >= MAX_NUM_CONN && listSize( FreeConn ) == 0 ) {
            /* have to wait */
            _waitForConn();
            /* start from begining */
            continue;
        }
        else {
            tmpIFuseConn = ( iFuseConn_t * ) removeFirstElementOfConcurrentList( FreeConn );
            if ( tmpIFuseConn == NULL ) {
                if ( listSize( ConnectedConn ) < MAX_NUM_CONN ) {
                    /* may cause num of conn > max num of conn */
                    /* get here when nothing free. make one */
                    tmpIFuseConn = newIFuseConn( &status );
                    if ( status < 0 ) {
                        _freeIFuseConn( tmpIFuseConn );
                        return status;
                    }

                    _useFreeIFuseConn( tmpIFuseConn );
                    addToConcurrentList( ConnectedConn, tmpIFuseConn );

                    *iFuseConn = tmpIFuseConn;
                    break;

                }
                _waitForConn();
                continue;
            }
            else {
                useIFuseConn( tmpIFuseConn );
                *iFuseConn = tmpIFuseConn;
                break;
            }
        }


    }	/* while *iFuseConn */

    if ( ++ConnManagerStarted == HIGH_NUM_CONN ) {
        /* don't do it the first time */

#ifdef USE_BOOST
        ConnManagerThr = new boost::thread( connManager );
#else
        status = pthread_create( &ConnManagerThr, pthread_attr_default, ( void * ( * )( void * ) ) connManager, ( void * ) NULL );
#endif
        if ( status < 0 ) {
            ConnManagerStarted--;
            rodsLog( LOG_ERROR, "pthread_create failure, status = %d", status );
        }
    }
    return 0;
}