summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul R. Eggert <eggert@cs.ucla.edu>2010-07-25 20:54:55 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2010-07-25 20:55:21 -0700
commitde949fc12dffef87e381a821c18887e4efdd1b00 (patch)
tree276f3cda75e30cb03baddb311434d486a0c16684
parent1563ffd2b1e63c48b5c7a04f8b60556ee56c7154 (diff)
downloadcoreutils-de949fc12dffef87e381a821c18887e4efdd1b00.tar.xz
sort: omit unnecessary mutex unlock+lock; simplify heap access
* src/sort.c (queue_pop): Omit unnecessary unlock+lock after pthread_cond_wait returns. Don't access "count" member of the heap; any efficiency gains should be quite minor, the access complicates this code, and "count" should be private anyway.
-rw-r--r--src/sort.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/sort.c b/src/sort.c
index ea2720f68..577521d68 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -3173,20 +3173,11 @@ queue_insert (struct merge_node_queue *queue, struct merge_node *node)
static inline struct merge_node *
queue_pop (struct merge_node_queue *queue)
{
- struct merge_node *node = NULL;
-
- while (!node)
- {
- pthread_mutex_lock (&queue->mutex);
- if (queue->priority_queue->count)
- node = heap_remove_top (queue->priority_queue);
- else
- {
- /* Go into conditional wait if no NODE is immediately available. */
- pthread_cond_wait (&queue->cond, &queue->mutex);
- }
- pthread_mutex_unlock (&queue->mutex);
- }
+ struct merge_node *node;
+ pthread_mutex_lock (&queue->mutex);
+ while (! (node = heap_remove_top (queue->priority_queue)))
+ pthread_cond_wait (&queue->cond, &queue->mutex);
+ pthread_mutex_unlock (&queue->mutex);
lock_node (node);
node->queued = false;
return node;