You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ma...@hyperreal.org on 1999/02/09 23:04:17 UTC

cvs commit: apache-apr/pthreads/src/main fdqueue.c

manoj       99/02/09 14:04:16

  Modified:    pthreads/src/main fdqueue.c
  Log:
  Optimization: don't pthread_cond_signal every time something is added to
  the queue, but only when there is a state change (empty -> not empty, full
  -> not full).
  
  Revision  Changes    Path
  1.2       +8 -3      apache-apr/pthreads/src/main/fdqueue.c
  
  Index: fdqueue.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/fdqueue.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- fdqueue.c	1999/02/03 17:50:09	1.1
  +++ fdqueue.c	1999/02/09 22:04:14	1.2
  @@ -33,12 +33,14 @@
       }
       queue->data[queue->tail].fd = fd;
       queue->data[queue->tail].addr = *addr;
  +    /* If the queue was empty, signal that it no longer is */
  +    if (queue->head == queue->tail) {
  +        pthread_cond_signal(&queue->not_empty);
  +    }
       queue->tail = (queue->tail + 1) % queue->bounds;
       if (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
           return FD_QUEUE_FAILURE;
       }
  -    if (pthread_cond_signal(&queue->not_empty) != 0)
  -        perror("signal didn't work :(");
       return FD_QUEUE_SUCCESS;
   }
   
  @@ -52,11 +54,14 @@
       }
       fd = queue->data[queue->head].fd;
       *addr = queue->data[queue->head].addr;
  +    /* If the queue was full, signal that it no longer is */
  +    if (queue->head == ((queue->tail + 1) % queue->bounds)) {
  +        pthread_cond_signal(&queue->not_full);
  +    }
       queue->head = (queue->head + 1) % queue->bounds;
       if (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
           return FD_QUEUE_FAILURE;
       }
  -    pthread_cond_signal(&queue->not_full);
       return fd;
   }