Navigation


Changeset 43:2db15632a63d in freeDiameter for libfreeDiameter/fifo.c


Ignore:
Timestamp:
Nov 25, 2009, 7:07:09 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added a large part of connection establishment logic, to test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfreeDiameter/fifo.c

    r25 r43  
    183183}
    184184
    185 /* Move the content of old into new, and update loc_update atomically */
    186 int fd_fifo_move ( struct fifo ** old, struct fifo * new, struct fifo ** loc_update )
     185/* Move the content of old into new, and update loc_update atomically. We leave the old queue empty but valid */
     186int fd_fifo_move ( struct fifo * old, struct fifo * new, struct fifo ** loc_update )
    187187{
    188188        struct fifo * q;
     
    190190       
    191191        TRACE_ENTRY("%p %p %p", old, new, loc_update);
    192         CHECK_PARAMS( old && CHECK_FIFO( *old ) && CHECK_FIFO( new ));
    193        
    194         q = *old;
    195         CHECK_PARAMS( ! q->data );
     192        CHECK_PARAMS( CHECK_FIFO( old ) && CHECK_FIFO( new ));
     193       
     194        CHECK_PARAMS( ! old->data );
    196195        if (new->high) {
    197196                TODO("Implement support for thresholds in fd_fifo_move...");
     
    199198       
    200199        /* Update loc_update */
    201         *old = NULL;
    202200        if (loc_update)
    203201                *loc_update = new;
    204202       
    205203        /* Lock the queues */
    206         CHECK_POSIX(  pthread_mutex_lock( &q->mtx )  );
     204        CHECK_POSIX(  pthread_mutex_lock( &old->mtx )  );
    207205        CHECK_POSIX(  pthread_mutex_lock( &new->mtx )  );
    208206       
    209207        /* Any waiting thread on the old queue returns an error */
    210         q->eyec = 0xdead;
    211         while (q->thrs) {
    212                 CHECK_POSIX(  pthread_cond_signal(&q->cond)  );
    213                 CHECK_POSIX(  pthread_mutex_unlock( &q->mtx ));
     208        old->eyec = 0xdead;
     209        while (old->thrs) {
     210                CHECK_POSIX(  pthread_cond_signal(&old->cond)  );
     211                CHECK_POSIX(  pthread_mutex_unlock( &old->mtx ));
    214212                pthread_yield();
    215                 CHECK_POSIX(  pthread_mutex_lock( &q->mtx )  );
     213                CHECK_POSIX(  pthread_mutex_lock( &old->mtx )  );
    216214                ASSERT( ++loops < 10 ); /* detect infinite loops */
    217215        }
    218216       
    219217        /* Move all data from old to new */
    220         fd_list_move_end( &new->list, &q->list );
    221         if (q->count && (!new->count)) {
     218        fd_list_move_end( &new->list, &old->list );
     219        if (old->count && (!new->count)) {
    222220                CHECK_POSIX(  pthread_cond_signal(&new->cond)  );
    223221        }
    224         new->count += q->count;
    225        
    226         /* Destroy old */
    227         CHECK_POSIX(  pthread_mutex_unlock( &q->mtx )  );
    228         CHECK_POSIX(  pthread_cond_destroy( &q->cond )  );
    229         CHECK_POSIX(  pthread_mutex_destroy( &q->mtx )  );
    230         free(q);
    231        
    232         /* Unlock new, we're done */
     222        new->count += old->count;
     223       
     224        /* Reset old */
     225        old->count = 0;
     226        old->eyec = FIFO_EYEC;
     227       
     228        /* Unlock, we're done */
    233229        CHECK_POSIX(  pthread_mutex_unlock( &new->mtx )  );
     230        CHECK_POSIX(  pthread_mutex_unlock( &old->mtx )  );
    234231       
    235232        return 0;
Note: See TracChangeset for help on using the changeset viewer.