Navigation


Changeset 21:bef197f6826f in freeDiameter for libfreeDiameter/fifo.c


Ignore:
Timestamp:
Oct 8, 2009, 8:05:16 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Backup before week-end, cnxctx and server in progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfreeDiameter/fifo.c

    r14 r21  
    136136}
    137137
    138 /* Delete a queue. It must be unused. */
     138/* Delete a queue. It must be empty. */
    139139int fd_fifo_del ( struct fifo  ** queue )
    140140{
    141141        struct fifo * q;
     142        int loops = 0;
    142143       
    143144        TRACE_ENTRY( "%p", queue );
     
    149150        CHECK_POSIX(  pthread_mutex_lock( &q->mtx )  );
    150151       
    151         if ((q->count != 0) || (q->thrs != 0) || (q->data != NULL)) {
    152                 TRACE_DEBUG(INFO, "The queue cannot be destroyed (%d, %d, %p)", q->count, q->thrs, q->data);
     152        /* Ok, now invalidate the queue */
     153        q->eyec = 0xdead;
     154       
     155        if ((q->count != 0) || (q->data != NULL)) {
     156                TRACE_DEBUG(INFO, "The queue cannot be destroyed (%d, %p)", q->count, q->data);
    153157                CHECK_POSIX_DO(  pthread_mutex_unlock( &q->mtx ), /* no fallback */  );
    154158                return EINVAL;
    155159        }
    156160       
     161        while (q->thrs) {
     162                CHECK_POSIX(  pthread_cond_signal(&q->cond)  );
     163                CHECK_POSIX(  pthread_mutex_unlock( &q->mtx ));
     164                pthread_yield();
     165                CHECK_POSIX(  pthread_mutex_lock( &q->mtx )  );
     166                ASSERT( ++loops < 10 ); /* detect infinite loops */
     167        }
     168       
    157169        /* sanity check */
    158170        ASSERT(FD_IS_LIST_EMPTY(&q->list));
    159        
    160         /* Ok, now invalidate the queue */
    161         q->eyec = 0xdead;
    162171       
    163172        /* And destroy it */
     
    379388awaken:
    380389        /* Check queue status */
     390        if (!CHECK_FIFO( queue )) {
     391                /* The queue is being destroyed */
     392                CHECK_POSIX(  pthread_mutex_unlock( &queue->mtx )  );
     393                TRACE_DEBUG(FULL, "The queue is being destroyed -> EPIPE");
     394                return EPIPE;
     395        }
     396               
    381397        if (queue->count > 0) {
    382398                /* There are items in the queue, so pick the first one */
Note: See TracChangeset for help on using the changeset viewer.