src/nc_thread.c
/*
 * Returns a fresh connection swapunit queue item.
 */
Returns a fresh connection swapunit queue item.
Returns a fresh connection swapunit queue item .
struct swapunit *
sui_new(void) {
    struct swapunit *item = NULL;
    pthread_mutex_lock(&sui_freelist_lock);
    if (sui_freelist) {
        item = sui_freelist;
        sui_freelist = item->next;
    }
    pthread_mutex_unlock(&sui_freelist_lock);
    if (NULL == item) {
        int i;
        item = nc_alloc(sizeof(struct swapunit) * SU_PER_ALLOC);
        if (NULL == item) {
            return NULL;
        }
        for (i = 2; i < SU_PER_ALLOC; i++)
            item[i - 1].next = &item[i];
        pthread_mutex_lock(&sui_freelist_lock);
        item[SU_PER_ALLOC - 1].next = sui_freelist;
        sui_freelist = &item[1];
        pthread_mutex_unlock(&sui_freelist_lock);
    }
    STAILQ_NEXT(item, nextsu) = NULL;
    return item;
}
struct swapunit * sui_new ( void ) { struct swapunit * item = NULL ; pthread_mutex_lock ( & sui_freelist_lock ) ; if ( sui_freelist ) { item = sui_freelist ; sui_freelist = item -> next ; } pthread_mutex_unlock ( & sui_freelist_lock ) ; if ( NULL == item ) { int i ; item = nc_alloc ( sizeof ( struct swapunit ) * SU_PER_ALLOC ) ; if ( NULL == item ) { return NULL ; } for ( i = 2 ; i < SU_PER_ALLOC ; i ++ ) item [ i - 1 ] . next = & item [ i ] ; pthread_mutex_lock ( & sui_freelist_lock ) ; item [ SU_PER_ALLOC - 1 ] . next = sui_freelist ; sui_freelist = & item [ 1 ] ; pthread_mutex_unlock ( & sui_freelist_lock ) ; } STAILQ_NEXT ( item , nextsu ) = NULL ; return item ; }
Returns a fresh connection swapunit queue item.
Returns a fresh connection swapunit queue item .
/* Allocate a bunch of items at once to reduce fragmentation */ /*
         * Link together all the new items except the first one
         * (which we'll return to the caller) for placement on
         * the freelist.
         */