Line data Source code
1 : /*
2 : * SPDX-License-Identifier: MPL-2.0
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * Copyright 2024 MonetDB Foundation;
9 : * Copyright August 2008 - 2023 MonetDB B.V.;
10 : * Copyright 1997 - July 2008 CWI.
11 : */
12 :
13 : /* This file should not be included in any file outside of this directory */
14 :
15 : #ifndef LIBGDK
16 : #error this file should not be included outside its source directory
17 : #endif
18 :
19 : /* persist hash heaps for persistent BATs */
20 : #define PERSISTENTHASH 1
21 :
22 : /* persist order index heaps for persistent BATs */
23 : #define PERSISTENTIDX 1
24 :
25 : /* persist strimp heaps for persistent BATs */
26 : #define PERSISTENTSTRIMP 1
27 :
28 : /* only check whether we exceed gdk_vm_maxsize when allocating heaps */
29 : #define SIZE_CHECK_IN_HEAPS_ONLY 1
30 :
31 : #include "gdk_system_private.h"
32 :
33 : enum heaptype {
34 : offheap,
35 : varheap,
36 : hashheap,
37 : imprintsheap,
38 : orderidxheap,
39 : strimpheap,
40 : dataheap
41 : };
42 :
43 : enum range_comp_t {
44 : range_before, /* search range fully before bat range */
45 : range_after, /* search range fully after bat range */
46 : range_atstart, /* search range before + inside */
47 : range_atend, /* search range inside + after */
48 : range_contains, /* search range contains bat range */
49 : range_inside, /* search range inside bat range */
50 : };
51 :
52 : bool ATOMisdescendant(int id, int parentid)
53 : __attribute__((__visibility__("hidden")));
54 : int ATOMunknown_find(const char *nme)
55 : __attribute__((__warn_unused_result__))
56 : __attribute__((__visibility__("hidden")));
57 : const char *ATOMunknown_name(int a)
58 : __attribute__((__visibility__("hidden")));
59 : void ATOMunknown_clean(void)
60 : __attribute__((__visibility__("hidden")));
61 : bool BATcheckhash(BAT *b)
62 : __attribute__((__visibility__("hidden")));
63 : bool BATcheckimprints(BAT *b)
64 : __attribute__((__visibility__("hidden")));
65 : gdk_return BATcheckmodes(BAT *b, bool persistent)
66 : __attribute__((__warn_unused_result__))
67 : __attribute__((__visibility__("hidden")));
68 : BAT *BATcreatedesc(oid hseq, int tt, bool heapnames, role_t role, uint16_t width)
69 : __attribute__((__visibility__("hidden")));
70 : void BATdelete(BAT *b)
71 : __attribute__((__visibility__("hidden")));
72 : void BATdestroy(BAT *b)
73 : __attribute__((__visibility__("hidden")));
74 : void BATfree(BAT *b)
75 : __attribute__((__visibility__("hidden")));
76 : gdk_return BATgroup_internal(BAT **groups, BAT **extents, BAT **histo, BAT *b, BAT *s, BAT *g, BAT *e, BAT *h, bool subsorted)
77 : __attribute__((__warn_unused_result__))
78 : __attribute__((__visibility__("hidden")));
79 : Hash *BAThash_impl(BAT *restrict b, struct canditer *restrict ci, const char *restrict ext)
80 : __attribute__((__visibility__("hidden")));
81 : void BAThashsave(BAT *b, bool dosync)
82 : __attribute__((__visibility__("hidden")));
83 : bool BATiscand(BAT *b)
84 : __attribute__((__visibility__("hidden")));
85 : BAT *BATload_intern(bat bid, bool lock)
86 : __attribute__((__visibility__("hidden")));
87 : gdk_return BATmaterialize(BAT *b, BUN cap)
88 : __attribute__((__warn_unused_result__))
89 : __attribute__((__visibility__("hidden")));
90 : gdk_return BATsave_iter(BAT *bd, BATiter *bi, BUN size)
91 : __attribute__((__visibility__("hidden")));
92 : void BATsetdims(BAT *b, uint16_t width)
93 : __attribute__((__visibility__("hidden")));
94 : gdk_return BBPcacheit(BAT *bn, bool lock)
95 : __attribute__((__warn_unused_result__))
96 : __attribute__((__visibility__("hidden")));
97 : gdk_return BBPchkfarms(void)
98 : __attribute__((__warn_unused_result__))
99 : __attribute__((__visibility__("hidden")));
100 : void BBPclear(bat bid)
101 : __attribute__((__visibility__("hidden")));
102 : void BBPdump(void) /* never called: for debugging only */
103 : __attribute__((__cold__));
104 : void BBPexit(void)
105 : __attribute__((__visibility__("hidden")));
106 : gdk_return BBPinit(bool allow_hge_upgrade)
107 : __attribute__((__visibility__("hidden")));
108 : bat BBPinsert(BAT *bn)
109 : __attribute__((__warn_unused_result__))
110 : __attribute__((__visibility__("hidden")));
111 : void BBPprintinfo(void)
112 : __attribute__((__visibility__("hidden")));
113 : int BBPselectfarm(role_t role, int type, enum heaptype hptype)
114 : __attribute__((__visibility__("hidden")));
115 : BUN binsearch(const oid *restrict indir, oid offset, int type, const void *restrict vals, const char * restrict vars, int width, BUN lo, BUN hi, const void *restrict v, int ordering, int last)
116 : __attribute__((__visibility__("hidden")));
117 : BUN binsearch_bte(const oid *restrict indir, oid offset, const bte *restrict vals, BUN lo, BUN hi, bte v, int ordering, int last)
118 : __attribute__((__visibility__("hidden")));
119 : BUN binsearch_sht(const oid *restrict indir, oid offset, const sht *restrict vals, BUN lo, BUN hi, sht v, int ordering, int last)
120 : __attribute__((__visibility__("hidden")));
121 : BUN binsearch_int(const oid *restrict indir, oid offset, const int *restrict vals, BUN lo, BUN hi, int v, int ordering, int last)
122 : __attribute__((__visibility__("hidden")));
123 : BUN binsearch_lng(const oid *restrict indir, oid offset, const lng *restrict vals, BUN lo, BUN hi, lng v, int ordering, int last)
124 : __attribute__((__visibility__("hidden")));
125 : #ifdef HAVE_HGE
126 : BUN binsearch_hge(const oid *restrict indir, oid offset, const hge *restrict vals, BUN lo, BUN hi, hge v, int ordering, int last)
127 : __attribute__((__visibility__("hidden")));
128 : #endif
129 : BUN binsearch_flt(const oid *restrict indir, oid offset, const flt *restrict vals, BUN lo, BUN hi, flt v, int ordering, int last)
130 : __attribute__((__visibility__("hidden")));
131 : BUN binsearch_dbl(const oid *restrict indir, oid offset, const dbl *restrict vals, BUN lo, BUN hi, dbl v, int ordering, int last)
132 : __attribute__((__visibility__("hidden")));
133 : Heap *createOIDXheap(BAT *b, bool stable)
134 : __attribute__((__visibility__("hidden")));
135 : void doHASHdestroy(BAT *b, Hash *hs)
136 : __attribute__((__visibility__("hidden")));
137 : void gdk_bbp_reset(void)
138 : __attribute__((__visibility__("hidden")));
139 : gdk_return GDKextend(const char *fn, size_t size)
140 : __attribute__((__warn_unused_result__))
141 : __attribute__((__visibility__("hidden")));
142 : gdk_return GDKextendf(int fd, size_t size, const char *fn)
143 : __attribute__((__warn_unused_result__))
144 : __attribute__((__visibility__("hidden")));
145 : int GDKfdlocate(int farmid, const char *nme, const char *mode, const char *ext)
146 : __attribute__((__visibility__("hidden")));
147 : FILE *GDKfilelocate(int farmid, const char *nme, const char *mode, const char *ext)
148 : __attribute__((__visibility__("hidden")));
149 : FILE *GDKfileopen(int farmid, const char *dir, const char *name, const char *extension, const char *mode)
150 : __attribute__((__visibility__("hidden")));
151 : char *GDKload(int farmid, const char *nme, const char *ext, size_t size, size_t *maxsize, storage_t mode)
152 : __attribute__((__visibility__("hidden")));
153 : gdk_return GDKmove(int farmid, const char *dir1, const char *nme1, const char *ext1, const char *dir2, const char *nme2, const char *ext2, bool report)
154 : __attribute__((__warn_unused_result__))
155 : __attribute__((__visibility__("hidden")));
156 : void *GDKmremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
157 : __attribute__((__visibility__("hidden")));
158 : gdk_return GDKremovedir(int farmid, const char *nme)
159 : __attribute__((__warn_unused_result__))
160 : __attribute__((__visibility__("hidden")));
161 : gdk_return GDKsave(int farmid, const char *nme, const char *ext, void *buf, size_t size, storage_t mode, bool dosync)
162 : __attribute__((__warn_unused_result__))
163 : __attribute__((__visibility__("hidden")));
164 : gdk_return GDKssort_rev(void *restrict h, void *restrict t, const void *restrict base, size_t n, int hs, int ts, int tpe)
165 : __attribute__((__warn_unused_result__))
166 : __attribute__((__visibility__("hidden")));
167 : gdk_return GDKssort(void *restrict h, void *restrict t, const void *restrict base, size_t n, int hs, int ts, int tpe)
168 : __attribute__((__warn_unused_result__))
169 : __attribute__((__visibility__("hidden")));
170 : gdk_return GDKtracer_init(const char *dbname, const char *dbtrace)
171 : __attribute__((__visibility__("hidden")));
172 : gdk_return GDKunlink(int farmid, const char *dir, const char *nme, const char *extension)
173 : __attribute__((__visibility__("hidden")));
174 : #define GDKwarning(format, ...) \
175 : GDKtracer_log(__FILE__, __func__, __LINE__, M_WARNING, \
176 : GDK, NULL, format, ##__VA_ARGS__)
177 : lng getBBPlogno(void)
178 : __attribute__((__visibility__("hidden")));
179 : lng getBBPtransid(void)
180 : __attribute__((__visibility__("hidden")));
181 : BUN HASHappend(BAT *b, BUN i, const void *v)
182 : __attribute__((__visibility__("hidden")));
183 : void HASHappend_locked(BAT *b, BUN i, const void *v)
184 : __attribute__((__visibility__("hidden")));
185 : void HASHfree(BAT *b)
186 : __attribute__((__visibility__("hidden")));
187 : BUN HASHdelete(BATiter *bi, BUN p, const void *v)
188 : __attribute__((__visibility__("hidden")));
189 : void HASHdelete_locked(BATiter *bi, BUN p, const void *v)
190 : __attribute__((__visibility__("hidden")));
191 : BUN HASHinsert(BATiter *bi, BUN p, const void *v)
192 : __attribute__((__visibility__("hidden")));
193 : void HASHinsert_locked(BATiter *bi, BUN p, const void *v)
194 : __attribute__((__visibility__("hidden")));
195 : BUN HASHmask(BUN cnt)
196 : __attribute__((__const__))
197 : __attribute__((__visibility__("hidden")));
198 : gdk_return HASHnew(Hash *h, int tpe, BUN size, BUN mask, BUN count, bool bcktonly)
199 : __attribute__((__visibility__("hidden")));
200 : gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize)
201 : __attribute__((__warn_unused_result__))
202 : __attribute__((__visibility__("hidden")));
203 : gdk_return HEAPcopy(Heap *dst, Heap *src, size_t offset)
204 : __attribute__((__warn_unused_result__))
205 : __attribute__((__visibility__("hidden")));
206 : void HEAPfree(Heap *h, bool remove)
207 : __attribute__((__visibility__("hidden")));
208 : gdk_return HEAPgrow(Heap **old, size_t size, bool mayshare)
209 : __attribute__((__visibility__("hidden")));
210 : gdk_return HEAPload(Heap *h, const char *nme, const char *ext, bool trunc)
211 : __attribute__((__warn_unused_result__))
212 : __attribute__((__visibility__("hidden")));
213 : void HEAP_recover(Heap *, const var_t *, BUN)
214 : __attribute__((__visibility__("hidden")));
215 : gdk_return HEAPsave(Heap *h, const char *nme, const char *ext, bool dosync, BUN free, MT_Lock *lock)
216 : __attribute__((__warn_unused_result__))
217 : __attribute__((__visibility__("hidden")));
218 : void IMPSdecref(Imprints *imprints, bool remove)
219 : __attribute__((__visibility__("hidden")));
220 : void IMPSfree(BAT *b)
221 : __attribute__((__visibility__("hidden")));
222 : int IMPSgetbin(int tpe, bte bits, const char *restrict bins, const void *restrict v)
223 : __attribute__((__visibility__("hidden")));
224 : void IMPSincref(Imprints *imprints)
225 : __attribute__((__visibility__("hidden")));
226 : #ifndef NDEBUG
227 : void IMPSprint(BAT *b) /* never called: for debugging only */
228 : __attribute__((__cold__));
229 : #endif
230 : double joincost(BAT *r, BUN lcount, struct canditer *rci, bool *hash, bool *phash, bool *cand)
231 : __attribute__((__visibility__("hidden")));
232 : void STRMPincref(Strimps *strimps)
233 : __attribute__((__visibility__("hidden")));
234 : void STRMPdecref(Strimps *strimps, bool remove)
235 : __attribute__((__visibility__("hidden")));
236 : void STRMPfree(BAT *b)
237 : __attribute__((__visibility__("hidden")));
238 : void MT_init_posix(void)
239 : __attribute__((__visibility__("hidden")));
240 : void *MT_mmap(const char *path, int mode, size_t len)
241 : __attribute__((__visibility__("hidden")));
242 : void *MT_mremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
243 : __attribute__((__visibility__("hidden")));
244 : int MT_msync(void *p, size_t len)
245 : __attribute__((__visibility__("hidden")));
246 : int MT_munmap(void *p, size_t len)
247 : __attribute__((__visibility__("hidden")));
248 : void OIDXfree(BAT *b)
249 : __attribute__((__visibility__("hidden")));
250 : void persistOIDX(BAT *b)
251 : __attribute__((__visibility__("hidden")));
252 : void PROPdestroy(BAT *b)
253 : __attribute__((__visibility__("hidden")));
254 : void PROPdestroy_nolock(BAT *b)
255 : __attribute__((__visibility__("hidden")));
256 : gdk_return rangejoin(BAT *r1, BAT *r2, BAT *l, BAT *rl, BAT *rh, struct canditer *lci, struct canditer *rci, bool li, bool hi, bool anti, bool symmetric, BUN maxsize)
257 : __attribute__((__warn_unused_result__))
258 : __attribute__((__visibility__("hidden")));
259 : void settailname(Heap *restrict tail, const char *restrict physnme, int tt, int width)
260 : __attribute__((__visibility__("hidden")));
261 : void strCleanHash(Heap *hp, bool rebuild)
262 : __attribute__((__visibility__("hidden")));
263 : gdk_return strHeap(Heap *d, size_t cap)
264 : __attribute__((__visibility__("hidden")));
265 : var_t strLocate(Heap *h, const char *v)
266 : __attribute__((__visibility__("hidden")));
267 : var_t strPut(BAT *b, var_t *dst, const void *v)
268 : __attribute__((__visibility__("hidden")));
269 : char *strRead(str a, size_t *dstlen, stream *s, size_t cnt)
270 : __attribute__((__visibility__("hidden")));
271 : ssize_t strToStr(char **restrict dst, size_t *restrict len, const char *restrict src, bool external)
272 : __attribute__((__visibility__("hidden")));
273 : gdk_return strWrite(const char *a, stream *s, size_t cnt)
274 : __attribute__((__visibility__("hidden")));
275 : gdk_return TMcommit(void)
276 : __attribute__((__visibility__("hidden")));
277 : gdk_return unshare_varsized_heap(BAT *b)
278 : __attribute__((__warn_unused_result__))
279 : __attribute__((__visibility__("hidden")));
280 : void VIEWboundsbi(BATiter *bi, BAT *view, BUN l, BUN h)
281 : __attribute__((__visibility__("hidden")));
282 : void VIEWdestroy(BAT *b)
283 : __attribute__((__visibility__("hidden")));
284 : BAT *virtualize(BAT *bn)
285 : __attribute__((__visibility__("hidden")));
286 :
287 : static inline bool
288 59 : imprintable(int tpe)
289 : {
290 103 : switch (ATOMbasetype(tpe)) {
291 : case TYPE_bte:
292 : case TYPE_sht:
293 : case TYPE_int:
294 : case TYPE_lng:
295 : #ifdef HAVE_HGE
296 : case TYPE_hge:
297 : #endif
298 : case TYPE_flt:
299 : case TYPE_dbl:
300 : return true;
301 9 : default: /* type not supported */
302 9 : return false;
303 : }
304 : }
305 :
306 : /* calculate the integer 2 logarithm (i.e. position of highest set
307 : * bit) of the argument (with a slight twist: 0 gives 0, 1 gives 1,
308 : * 0x8 to 0xF give 4, etc.) */
309 : static inline unsigned
310 11440 : ilog2(BUN x)
311 : {
312 11440 : if (x == 0)
313 : return 0;
314 : #if defined(__GNUC__)
315 : #if SIZEOF_BUN == 8
316 11440 : return (unsigned) (64 - __builtin_clzll((unsigned long long) x));
317 : #else
318 : return (unsigned) (32 - __builtin_clz((unsigned) x));
319 : #endif
320 : #elif defined(_MSC_VER)
321 : unsigned long n;
322 : if (
323 : #if SIZEOF_BUN == 8
324 : _BitScanReverse64(&n, (unsigned __int64) x)
325 : #else
326 : _BitScanReverse(&n, (unsigned long) x)
327 : #endif
328 : )
329 : return (unsigned) n + 1;
330 : else
331 : return 0;
332 : #else
333 : unsigned n = 0;
334 : BUN y;
335 :
336 : /* use a "binary search" method */
337 : #if SIZEOF_BUN == 8
338 : if ((y = x >> 32) != 0) {
339 : x = y;
340 : n += 32;
341 : }
342 : #endif
343 : if ((y = x >> 16) != 0) {
344 : x = y;
345 : n += 16;
346 : }
347 : if ((y = x >> 8) != 0) {
348 : x = y;
349 : n += 8;
350 : }
351 : if ((y = x >> 4) != 0) {
352 : x = y;
353 : n += 4;
354 : }
355 : if ((y = x >> 2) != 0) {
356 : x = y;
357 : n += 2;
358 : }
359 : if ((y = x >> 1) != 0) {
360 : x = y;
361 : n += 1;
362 : }
363 : return n + (x != 0);
364 : #endif
365 : }
366 :
367 : /* some macros to help print info about BATs when using ALGODEBUG */
368 : #define ALGOBATFMT "%s#" BUNFMT "@" OIDFMT "[%s%s]%s%s%s%s%s%s%s%s%s"
369 : #define ALGOBATPAR(b) \
370 : BATgetId(b), \
371 : BATcount(b), \
372 : b->hseqbase, \
373 : ATOMname(b->ttype), \
374 : b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"", \
375 : !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T", \
376 : BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "", \
377 : b->tsorted ? "S" : b->tnosorted ? "!s" : "", \
378 : b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "", \
379 : b->tkey ? "K" : b->tnokey[1] ? "!k" : "", \
380 : b->tnonil ? "N" : "", \
381 : b->thash ? "H" : "", \
382 : b->torderidx ? "O" : "", \
383 : b->timprints ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->timprints ? "(I)" : ""
384 : /* use ALGOOPTBAT* when BAT is optional (can be NULL) */
385 : #define ALGOOPTBATFMT "%s%s" BUNFMT "%s" OIDFMT "%s%s%s%s%s%s%s%s%s%s%s%s%s"
386 : #define ALGOOPTBATPAR(b) \
387 : b ? BATgetId(b) : "", \
388 : b ? "#" : "", \
389 : b ? BATcount(b) : 0, \
390 : b ? "@" : "", \
391 : b ? b->hseqbase : 0, \
392 : b ? "[" : "", \
393 : b ? ATOMname(b->ttype) : "", \
394 : b ? b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"" : "", \
395 : b ? "]" : "", \
396 : b ? !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T" : "", \
397 : b ? BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && b->tvheap && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "" : "", \
398 : b ? b->tsorted ? "S" : b->tnosorted ? "!s" : "" : "", \
399 : b ? b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "" : "", \
400 : b ? b->tkey ? "K" : b->tnokey[1] ? "!k" : "" : "", \
401 : b && b->tnonil ? "N" : "", \
402 : b && b->thash ? "H" : "", \
403 : b && b->torderidx ? "O" : "", \
404 : b ? b->timprints ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->timprints ? "(I)" : "" : ""
405 :
406 : #ifdef __SANITIZE_THREAD__
407 : #define BBP_BATMASK 31
408 : #else
409 : #define BBP_BATMASK ((1 << (SIZEOF_SIZE_T + 5)) - 1)
410 : #endif
411 :
412 : struct PROPrec {
413 : enum prop_t id;
414 : ValRecord v;
415 : struct PROPrec *next; /* simple chain of properties */
416 : };
417 :
418 : struct Imprints {
419 : bte bits; /* how many bits in imprints */
420 : Heap imprints;
421 : void *bins; /* pointer into imprints heap (bins borders) */
422 : BUN *stats; /* pointer into imprints heap (stats per bin) */
423 : void *imps; /* pointer into imprints heap (bit vectors) */
424 : void *dict; /* pointer into imprints heap (dictionary) */
425 : BUN impcnt; /* counter for imprints */
426 : BUN dictcnt; /* counter for cache dictionary */
427 : };
428 :
429 : typedef uint64_t strimp_masks_t; /* TODO: make this a sparse matrix */
430 :
431 : struct Strimps {
432 : Heap strimps;
433 : uint8_t *sizes_base; /* pointer into strimps heap (pair sizes) */
434 : uint8_t *pairs_base; /* pointer into strimps heap (pairs start) */
435 : void *bitstrings_base; /* pointer into strimps heap (bitstrings
436 : * start) bitstrings_base is a pointer
437 : * to uint64_t */
438 : size_t rec_cnt; /* reconstruction counter: how many
439 : * bitstrings were added after header
440 : * construction. Currently unused. */
441 : strimp_masks_t *masks; /* quick access to masks for
442 : * bitstring construction */
443 : };
444 :
445 : #ifdef HAVE_RTREE
446 : struct RTree {
447 : ATOMIC_TYPE refs; /* counter for logical references to the rtree */
448 : rtree_t *rtree; /* rtree structure */
449 : bool destroy; /* destroy rtree when there are no more logical references */
450 : };
451 : #endif
452 :
453 : typedef struct {
454 : MT_Lock swap;
455 : } batlock_t;
456 :
457 : typedef char long_str[IDLENGTH]; /* standard GDK static string */
458 :
459 : #define MAXFARMS 32
460 :
461 : extern struct BBPfarm_t {
462 : uint32_t roles; /* bitmask of allowed roles */
463 : const char *dirname; /* farm directory */
464 : FILE *lock_file;
465 : } BBPfarms[MAXFARMS];
466 :
467 : extern batlock_t GDKbatLock[BBP_BATMASK + 1];
468 : extern size_t GDK_mmap_minsize_persistent; /* size after which we use memory mapped files for persistent heaps */
469 : extern size_t GDK_mmap_minsize_transient; /* size after which we use memory mapped files for transient heaps */
470 : extern size_t GDK_mmap_pagesize; /* mmap granularity */
471 :
472 : #define BATcheck(tst, err) \
473 : do { \
474 : if ((tst) == NULL) { \
475 : GDKerror("BAT required.\n"); \
476 : return (err); \
477 : } \
478 : } while (0)
479 : #define ERRORcheck(tst, msg, err) \
480 : do { \
481 : if (tst) { \
482 : GDKerror(msg); \
483 : return (err); \
484 : } \
485 : } while (0)
486 :
487 : #define GDKswapLock(x) GDKbatLock[(x)&BBP_BATMASK].swap
488 :
489 : #define HEAPREMOVE ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 1))
490 : #define DELAYEDREMOVE ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2))
491 : #define HEAPREFS (((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2)) - 1)
492 :
493 : /* when the number of updates to a BAT is less than 1 in this number, we
494 : * keep the unique_est property */
495 : #define GDK_UNIQUE_ESTIMATE_KEEP_FRACTION 1000
496 : extern BUN gdk_unique_estimate_keep_fraction; /* should become a define once */
497 : /* if the number of unique values is less than 1 in this number, we
498 : * destroy the hash rather than update it in HASH{append,insert,delete} */
499 : #define HASH_DESTROY_UNIQUES_FRACTION 1000
500 : extern BUN hash_destroy_uniques_fraction; /* likewise */
501 : /* if the estimated number of unique values is less than 1 in this
502 : * number, don't build a hash table to do a hashselect */
503 : #define NO_HASH_SELECT_FRACTION 1000
504 : extern dbl no_hash_select_fraction; /* same here */
505 : /* if the hash chain is longer than this number, we delete the hash
506 : * rather than maintaining it in HASHdelete */
507 : #define HASH_DESTROY_CHAIN_LENGTH 1000
508 : extern BUN hash_destroy_chain_length;
509 :
510 : #if !defined(NDEBUG) && !defined(__COVERITY__)
511 : /* see comment in gdk.h */
512 : #ifdef __GNUC__
513 : #define GDKmremap(p, m, oa, os, ns) \
514 : ({ \
515 : const char *_path = (p); \
516 : int _mode = (m); \
517 : void *_oa = (oa); \
518 : size_t _os = (os); \
519 : size_t *_ns = (ns); \
520 : size_t _ons = *_ns; \
521 : void *_res = GDKmremap(_path, _mode, _oa, _os, _ns); \
522 : TRC_DEBUG(ALLOC, \
523 : "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n", \
524 : _path ? _path : "NULL", (unsigned) _mode, \
525 : _oa, _os, _ons, *_ns, _res); \
526 : _res; \
527 : })
528 : #else
529 : static inline void *
530 : GDKmremap_debug(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
531 : {
532 : size_t orig_new_size = *new_size;
533 : void *res = GDKmremap(path, mode, old_address, old_size, new_size);
534 : TRC_DEBUG(ALLOC, "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n",
535 : path ? path : "NULL", (unsigned) mode,
536 : old_address, old_size, orig_new_size, *new_size, res);
537 : return res;
538 : }
539 : #define GDKmremap(p, m, oa, os, ns) GDKmremap_debug(p, m, oa, os, ns)
540 :
541 : #endif
542 : #endif
|