Graphviz
13.0.0~dev.20241220.2304
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
26
static
TLS
int (*
gv_sort_compar
)(
const
void
*,
const
void
*,
void
*);
27
static
TLS
void
*
gv_sort_arg
;
28
29
static
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
35
static
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
48
gv_sort_compar
=
NULL
;
49
gv_sort_arg
=
NULL
;
50
}
NULL
node NULL
Definition
grammar.y:163
gv_sort_arg
static TLS void * gv_sort_arg
Definition
sort.h:27
gv_sort_compar
static TLS int(* gv_sort_compar)(const void *, const void *, void *)
Definition
sort.h:26
gv_sort
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
gv_sort_compar_wrapper
static int gv_sort_compar_wrapper(const void *a, const void *b)
Definition
sort.h:29
TLS
#define TLS
thread-local storage specifier
Definition
sort.h:23
lib
util
sort.h
Generated by
1.9.8