renamed GMX_THREADS to GMX_THREAD_MPI
[gromacs.git] / include / gmx_sort.h
blobc1ef471b90232f32ce6d6914befc6101258ff773
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 *
4 * This file is part of Gromacs Copyright (c) 1991-2010
5 * David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * To help us fund GROMACS development, we humbly ask that you cite
13 * the research papers on the package. Check out http://www.gromacs.org
15 * And Hey:
16 * Gnomes, ROck Monsters And Chili Sauce
18 #ifndef _GMX_SORT_H_
19 #define _GMX_SORT_H_
21 /** @file gmx_sort.h
23 * @brief Portable implementation of thread-safe sort routines.
26 * This module provides a Gromacs version of the qsort() routine defined.
27 * It is not highly optimized, but it is thread safe, i.e. multiple threads
28 * can simultaneously call gmx_qsort with different data.
31 #include <stdlib.h>
33 #ifdef __cplusplus
34 extern "C"
36 #endif
37 #if 0
38 } /* fixes auto-indentation problems */
39 #endif
43 * @param base Pointer to first element in list to sort
44 * @param nmemb Number of elements in list
45 * @param size Size in bytes of each element
46 * @param compar Comparison function that takes two pointers to elements
47 * being compared as arguments. The function should return an
48 * integer less than, equal to, or greater than zero if the
49 * first argument is considered to be respectively less than,
50 * equal to, or greater than the second.
52 void
53 gmx_qsort(void * base,
54 size_t nmemb,
55 size_t size,
56 int (*compar)(const void *, const void *));
59 #ifdef GMX_THREAD_MPI
60 /* Some implementations of qsort are not threadsafe.
61 * For instance qsort in glibc contains a bug which makes it non-threadsafe:
62 * http://sources.redhat.com/bugzilla/show_bug.cgi?id=11655
64 #define qsort_threadsafe gmx_qsort
65 #else
66 /* System qsort might be faster than our own */
67 #define qsort_threadsafe qsort
68 #endif
71 #ifdef __cplusplus
73 #endif
76 #endif /* _GMX_SORT_H_ */