LCOV - code coverage report
Current view: top level - gdk - gdk_private.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 8 100.0 %
Date: 2025-03-25 20:06:35 Functions: 0 0 -

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

Generated by: LCOV version 1.14