forked from open-io/oio-sds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoioext.h
121 lines (82 loc) · 3.49 KB
/
oioext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
OpenIO SDS core library
Copyright (C) 2015-2017 OpenIO SAS, as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
*/
#ifndef OIO_SDS__core__oioext_h
# define OIO_SDS__core__oioext_h 1
#ifdef __cplusplus
extern "C" {
#endif
#include <glib.h>
#include <json-c/json.h>
// Return -1 if A<B, 0 if A==B, 1 if A>B
#define CMP(a,b) (((a) > (b)) - ((a) < (b)))
#define BOOL(C) ((C)!=0)
#define MACRO_COND(C,A,B) ((B) ^ (((A)^(B)) & -BOOL(C)))
#define OIO_TEST_INIT(argc,argv) oio_ext_init_test(&argc,&argv)
#define HC_TEST_INIT(argc,argv) OIO_TEST_INIT(argc,argv)
void oio_ext_init_test (int *argc, char ***argv);
/** Shuffles the single linked list. The original <src> MUST NOT be reused. */
GSList * oio_ext_gslist_shuffle(GSList *src);
/** Shuffles <array> in place. <len> is the len of the array. <len> must be
* greater than 1. */
void oio_ext_array_shuffle (gpointer *array, gsize len);
/** Reuses the pointers of t0 and t1 to buuld a new NULL-terminated array */
void ** oio_ext_array_concat (void **t0, void **t1);
/** Sorts 'src' in place, placing first the items with a TRUE predicate
* then the items with a FALSE predicate */
gsize oio_ext_array_partition (gpointer *array, gsize len,
gboolean (*predicate)(gconstpointer));
struct oio_ext_json_mapping_s {
const char *name;
struct json_object **out;
int type;
unsigned int mandatory;
};
/** In one call, extract all the fields described in <tab> from the JSON
* object j. */
GError * oio_ext_extract_json (struct json_object *j,
struct oio_ext_json_mapping_s *tab);
/** Set a thread-local variable with a copy of the given request id. */
void oio_ext_set_reqid (const char *reqid);
/** Calls oio_ext_set_reqid() with a randomly generated string */
void oio_ext_set_random_reqid (void);
/* DO NOT FREE ... In facts, DO NOT EVEN CONSIDER USING THIS FUNCTION!
* Gets the PRNG associated to the local thread, and allocates on if none
* already present. Returns THE pointer locally stored. Freeing it will break
* things and make the world collapse. Freeing will cause Ragnarok, Mappo and
* Al-Qiyamah all together. */
GRand * oio_ext_local_prng (void);
gboolean oio_ext_rand_boolean (void);
gdouble oio_ext_rand_double (void);
guint32 oio_ext_rand_int (void);
gint32 oio_ext_rand_int_range (gint32 low, gint32 up);
/** Get a request-id stored in the thread-local, or NULL if not set */
const char * oio_ext_get_reqid (void);
gint64 oio_ext_get_deadline(void);
void oio_ext_set_deadline(gint64 deadline);
gboolean oio_ext_is_admin(void);
void oio_ext_set_admin(const gboolean admin);
const gchar *oio_ext_get_user_agent(void);
void oio_ext_set_user_agent(const gchar *user_agent);
gint64 oio_ext_real_time (void);
gint64 oio_ext_monotonic_time (void);
time_t oio_ext_real_seconds (void);
time_t oio_ext_monotonic_seconds (void);
gdouble oio_sys_cpu_idle (void);
gdouble oio_sys_io_idle (const char *vol);
gdouble oio_sys_space_idle (const char *vol);
#ifdef __cplusplus
}
#endif
#endif /*OIO_SDS__core__oioext_h*/