MCPcopy Create free account
hub / github.com/coreutils/coreutils / sortlines

Function sortlines

src/sort.c:3892–3934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3890 have been merged. */
3891
3892static void
3893sortlines (struct line *restrict lines, size_t nthreads,
3894 size_t total_lines, struct merge_node *node,
3895 struct merge_node_queue *queue, FILE *tfp, char const *temp_output)
3896{
3897 size_t nlines = node->nlo + node->nhi;
3898
3899 /* Calculate thread arguments. */
3900 size_t lo_threads = nthreads / 2;
3901 size_t hi_threads = nthreads - lo_threads;
3902 pthread_t thread;
3903 struct thread_args args = {lines, lo_threads, total_lines,
3904 node->lo_child, queue, tfp, temp_output};
3905
3906 if (nthreads > 1 && SUBTHREAD_LINES_HEURISTIC <= nlines
3907 && pthread_create (&thread, NULL, sortlines_thread, &args) == 0)
3908 {
3909 sortlines (lines - node->nlo, hi_threads, total_lines,
3910 node->hi_child, queue, tfp, temp_output);
3911 pthread_join (thread, NULL);
3912 }
3913 else
3914 {
3915 /* Nthreads = 1, this is a leaf NODE, or pthread_create failed.
3916 Sort with 1 thread. */
3917 size_t nlo = node->nlo;
3918 size_t nhi = node->nhi;
3919 struct line *temp = lines - total_lines;
3920 if (1 < nhi)
3921 sequential_sort (lines - nlo, nhi, temp - nlo / 2, false);
3922 if (1 < nlo)
3923 sequential_sort (lines, nlo, temp, false);
3924
3925 /* Update merge NODE. No need to lock yet. */
3926 node->lo = lines;
3927 node->hi = lines - nlo;
3928 node->end_lo = lines - nlo;
3929 node->end_hi = lines - nlo - nhi;
3930
3931 queue_insert (queue, node);
3932 merge_loop (queue, total_lines, tfp, temp_output);
3933 }
3934}
3935
3936/* Scan through FILES[NTEMPS .. NFILES-1] looking for files that are
3937 the same as OUTFILE. If found, replace each with the same

Callers 2

sortlines_threadFunction · 0.85
sortFunction · 0.85

Calls 3

sequential_sortFunction · 0.85
queue_insertFunction · 0.85
merge_loopFunction · 0.85

Tested by

no test coverage detected