コード例 #1
0
ファイル: iFuseLib.Conn.cpp プロジェクト: hurngchunlee/irods
void
connManager() {
    time_t curTime;
    iFuseConn_t *tmpIFuseConn;
    ListNode *node;
    List *TimeOutList = newListNoRegion();

    while ( 1 ) {
        curTime = time( NULL );

        /* exceed high water mark for number of connection ? */
        if ( listSize( ConnectedConn ) > HIGH_NUM_CONN ) {

            LOCK_STRUCT( *ConnectedConn );
            int disconnTarget = _listSize( ConnectedConn ) - HIGH_NUM_CONN;
            node = ConnectedConn->list->head;
            while ( node != NULL ) {
                tmpIFuseConn = ( iFuseConn_t * ) node->value;
                if ( tmpIFuseConn->inuseCnt == 0 && tmpIFuseConn->pendingCnt == 0 && curTime - tmpIFuseConn->actTime > IFUSE_CONN_TIMEOUT ) {
                    listAppendNoRegion( TimeOutList, tmpIFuseConn );

                }
                node = node->next;
            }
            UNLOCK_STRUCT( *ConnectedConn );

            node = TimeOutList->head;
            int disconned = 0;
            while ( node != NULL && disconned < disconnTarget ) {
                tmpIFuseConn = ( iFuseConn_t * ) node->value;
                LOCK_STRUCT( *tmpIFuseConn );
                if ( tmpIFuseConn->inuseCnt == 0 && tmpIFuseConn->pendingCnt == 0 && curTime - tmpIFuseConn->actTime > IFUSE_CONN_TIMEOUT ) {
                    removeFromConcurrentList2( FreeConn, tmpIFuseConn );
                    removeFromConcurrentList2( ConnectedConn, tmpIFuseConn );
                    if ( tmpIFuseConn->status == 0 ) { /* no struct is referring to it, we can unlock it and free it */
                        UNLOCK_STRUCT( *tmpIFuseConn );
                        /* rodsLog(LOG_ERROR, "[FREE IFUSE CONN] %s:%d %p", __FILE__, __LINE__, tmpIFuseConn); */
                        _freeIFuseConn( tmpIFuseConn );
                    }
                    else {   /* set to timed out */
                        _ifuseDisconnect( tmpIFuseConn );
                        UNLOCK_STRUCT( *tmpIFuseConn );
                    }
                    disconned ++;
                }
                else {
                    UNLOCK_STRUCT( *tmpIFuseConn );
                }
                node = node->next;
            }
            clearListNoRegion( TimeOutList );
        }

        notifyWait( &connReqWait.mutex, &connReqWait.cond );
        timeoutWait( &ConnManagerLock, &ConnManagerCond, CONN_MANAGER_SLEEP_TIME );

    }
    deleteListNoRegion( TimeOutList );
}
コード例 #2
0
ファイル: iFuseLib.Conn.cpp プロジェクト: hurngchunlee/irods
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;
}
コード例 #3
0
ファイル: iFuseLib.Conn.cpp プロジェクト: dthain/irods
void
connManager() {
    time_t curTime;
    iFuseConn_t *tmpIFuseConn;
    ListNode *node;
    List *TimeOutList = newListNoRegion();

    while ( 1 ) {
        curTime = time( NULL );

        /* exceed high water mark for number of connection ? */
        if ( listSize( ConnectedConn ) > HIGH_NUM_CONN ) {

            LOCK_STRUCT( *ConnectedConn );
            int disconnTarget = _listSize( ConnectedConn ) - HIGH_NUM_CONN;
            node = ConnectedConn->list->head;
            while ( node != NULL ) {
                tmpIFuseConn = ( iFuseConn_t * ) node->value;
                if ( tmpIFuseConn->inuseCnt == 0 && tmpIFuseConn->pendingCnt == 0 && curTime - tmpIFuseConn->actTime > IFUSE_CONN_TIMEOUT ) {
                    listAppendNoRegion( TimeOutList, tmpIFuseConn );

                }
                node = node->next;            
            }
            UNLOCK_STRUCT( *ConnectedConn );

            node = TimeOutList->head;
            int disconned = 0;
            while ( node != NULL && disconned < disconnTarget ) {
                tmpIFuseConn = ( iFuseConn_t * ) node->value;
                LOCK_STRUCT( *tmpIFuseConn );
                if ( tmpIFuseConn->inuseCnt == 0 && tmpIFuseConn->pendingCnt == 0 && curTime - tmpIFuseConn->actTime > IFUSE_CONN_TIMEOUT ) {
                    removeFromConcurrentList2( FreeConn, tmpIFuseConn );
                    removeFromConcurrentList2( ConnectedConn, tmpIFuseConn );
                    if ( tmpIFuseConn->status == 0 ) { /* no struct is referring to it, we can unlock it and free it */
                        UNLOCK_STRUCT( *tmpIFuseConn );
                        /* rodsLog(LOG_ERROR, "[FREE IFUSE CONN] %s:%d %p", __FILE__, __LINE__, tmpIFuseConn); */
                        _freeIFuseConn( tmpIFuseConn );
                    }
                    else {   /* set to timed out */
                        _ifuseDisconnect( tmpIFuseConn );
                        UNLOCK_STRUCT( *tmpIFuseConn );
                    }
                    disconned ++;
                }
                else {
                    UNLOCK_STRUCT( *tmpIFuseConn );
                }
                node = node->next;
            }
            clearListNoRegion( TimeOutList );
        }

        while ( listSize( ConnectedConn ) <= MAX_NUM_CONN || listSize( FreeConn ) != 0 ) {
            /* signal one in the wait queue */
            connReqWait_t *myConnReqWait = ( connReqWait_t * ) removeFirstElementOfConcurrentList( ConnReqWaitQue );
            /* if there is no conn req left, exit loop */
            if ( myConnReqWait == NULL ) {
                break;
            }
            myConnReqWait->state = 1;
            notifyTimeoutWait( &myConnReqWait->mutex, &myConnReqWait->cond );
        }
#if 0
        rodsSleep( CONN_MANAGER_SLEEP_TIME, 0 );
#else
        timeoutWait( &ConnManagerLock, &ConnManagerCond, CONN_MANAGER_SLEEP_TIME );
#endif


    }
    deleteListNoRegion( TimeOutList );
}
コード例 #4
0
ファイル: iFuseLib.Conn.cpp プロジェクト: dthain/irods
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;
}