示例#1
0
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
int _freeIFuseConn(iFuseConn_t *tmpIFuseConn) {
	_ifuseDisconnect(tmpIFuseConn);
	FREE_STRUCT_LOCK(*tmpIFuseConn);
	FREE_LOCK(tmpIFuseConn->inuseLock);
	free (tmpIFuseConn);
	return 0;

}
示例#3
0
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
void ifuseDisconnect( iFuseConn_t *tmpIFuseConn ) {
    LOCK_STRUCT( *tmpIFuseConn );
    _ifuseDisconnect( tmpIFuseConn );
    UNLOCK_STRUCT( *tmpIFuseConn );
}