Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
sort.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <assert.h>
13#include <stdlib.h>
14
16#ifdef _MSC_VER
17#define TLS __declspec(thread)
18#elif defined(__GNUC__)
19#define TLS __thread
20#else
21// assume this environment does not support threads and fall back to (thread
22// unsafe) globals
23#define TLS /* nothing */
24#endif
25
26static TLS int (*gv_sort_compar)(const void *, const void *, void *);
27static TLS void *gv_sort_arg;
28
29static inline int gv_sort_compar_wrapper(const void *a, const void *b) {
30 assert(gv_sort_compar != NULL && "no comparator set in gv_sort");
31 return gv_sort_compar(a, b, gv_sort_arg);
32}
33
35static inline void gv_sort(void *base, size_t nmemb, size_t size,
36 int (*compar)(const void *, const void *, void *),
37 void *arg) {
38 assert(gv_sort_compar == NULL && gv_sort_arg == NULL &&
39 "unsupported recursive call to gv_sort");
40
41 gv_sort_compar = compar;
42 gv_sort_arg = arg;
43
44 if (nmemb > 1) {
45 qsort(base, nmemb, size, gv_sort_compar_wrapper);
46 }
47
50}
node NULL
Definition grammar.y:149
static TLS void * gv_sort_arg
Definition sort.h:27
static TLS int(* gv_sort_compar)(const void *, const void *, void *)
Definition sort.h:26
static void gv_sort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *arg)
qsort with an extra state parameter, ala qsort_r
Definition sort.h:35
static int gv_sort_compar_wrapper(const void *a, const void *b)
Definition sort.h:29
#define TLS
thread-local storage specifier
Definition sort.h:23