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: 2024-11-15 19:37:45 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 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             : FILE *GDKfileopen(int farmid, const char *dir, const char *name, const char *extension, const char *mode)
     140             :         __attribute__((__visibility__("hidden")));
     141             : char *GDKload(int farmid, const char *nme, const char *ext, size_t size, size_t *maxsize, storage_t mode)
     142             :         __attribute__((__visibility__("hidden")));
     143             : 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)
     144             :         __attribute__((__warn_unused_result__))
     145             :         __attribute__((__visibility__("hidden")));
     146             : void *GDKmremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     147             :         __attribute__((__visibility__("hidden")));
     148             : gdk_return GDKremovedir(int farmid, const char *nme)
     149             :         __attribute__((__warn_unused_result__))
     150             :         __attribute__((__visibility__("hidden")));
     151             : gdk_return GDKsave(int farmid, const char *nme, const char *ext, void *buf, size_t size, storage_t mode, bool dosync)
     152             :         __attribute__((__warn_unused_result__))
     153             :         __attribute__((__visibility__("hidden")));
     154             : gdk_return GDKrsort(void *restrict h, void *restrict t, size_t n, size_t hs, size_t ts, bool reverse, bool isuuid)
     155             :         __attribute__((__warn_unused_result__))
     156             :         __attribute__((__visibility__("hidden")));
     157             : gdk_return GDKssort_rev(void *restrict h, void *restrict t, const void *restrict base, size_t n, int hs, int ts, int tpe)
     158             :         __attribute__((__warn_unused_result__))
     159             :         __attribute__((__visibility__("hidden")));
     160             : gdk_return GDKssort(void *restrict h, void *restrict t, const void *restrict base, size_t n, int hs, int ts, int tpe)
     161             :         __attribute__((__warn_unused_result__))
     162             :         __attribute__((__visibility__("hidden")));
     163             : gdk_return GDKtracer_init(const char *dbname, const char *dbtrace)
     164             :         __attribute__((__visibility__("hidden")));
     165             : gdk_return GDKunlink(int farmid, const char *dir, const char *nme, const char *extension)
     166             :         __attribute__((__visibility__("hidden")));
     167             : lng getBBPlogno(void)
     168             :         __attribute__((__visibility__("hidden")));
     169             : BUN HASHappend(BAT *b, BUN i, const void *v)
     170             :         __attribute__((__visibility__("hidden")));
     171             : void HASHappend_locked(BAT *b, BUN i, const void *v)
     172             :         __attribute__((__visibility__("hidden")));
     173             : void HASHfree(BAT *b)
     174             :         __attribute__((__visibility__("hidden")));
     175             : BUN HASHdelete(BATiter *bi, BUN p, const void *v)
     176             :         __attribute__((__visibility__("hidden")));
     177             : void HASHdelete_locked(BATiter *bi, BUN p, const void *v)
     178             :         __attribute__((__visibility__("hidden")));
     179             : BUN HASHinsert(BATiter *bi, BUN p, const void *v)
     180             :         __attribute__((__visibility__("hidden")));
     181             : void HASHinsert_locked(BATiter *bi, BUN p, const void *v)
     182             :         __attribute__((__visibility__("hidden")));
     183             : __attribute__((__const__))
     184             : static inline BUN
     185      835950 : HASHmask(BUN cnt)
     186             : {
     187      835950 :         cnt = cnt * 8 / 7;
     188      835950 :         if (cnt < BATTINY)
     189       30168 :                 cnt = BATTINY;
     190      598498 :         return cnt;
     191             : }
     192             : gdk_return HASHnew(Hash *h, int tpe, BUN size, BUN mask, BUN count, bool bcktonly)
     193             :         __attribute__((__visibility__("hidden")));
     194             : gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize)
     195             :         __attribute__((__warn_unused_result__))
     196             :         __attribute__((__visibility__("hidden")));
     197             : gdk_return HEAPcopy(Heap *dst, Heap *src, size_t offset)
     198             :         __attribute__((__warn_unused_result__))
     199             :         __attribute__((__visibility__("hidden")));
     200             : void HEAPfree(Heap *h, bool remove)
     201             :         __attribute__((__visibility__("hidden")));
     202             : gdk_return HEAPgrow(Heap **old, size_t size, bool mayshare)
     203             :         __attribute__((__visibility__("hidden")));
     204             : gdk_return HEAPload(Heap *h, const char *nme, const char *ext, bool trunc)
     205             :         __attribute__((__warn_unused_result__))
     206             :         __attribute__((__visibility__("hidden")));
     207             : void HEAP_recover(Heap *, const var_t *, BUN)
     208             :         __attribute__((__visibility__("hidden")));
     209             : gdk_return HEAPsave(Heap *h, const char *nme, const char *ext, bool dosync, BUN free, MT_Lock *lock)
     210             :         __attribute__((__warn_unused_result__))
     211             :         __attribute__((__visibility__("hidden")));
     212             : double joincost(BAT *r, BUN lcount, struct canditer *rci, bool *hash, bool *phash, bool *cand)
     213             :         __attribute__((__visibility__("hidden")));
     214             : void STRMPincref(Strimps *strimps)
     215             :         __attribute__((__visibility__("hidden")));
     216             : void STRMPdecref(Strimps *strimps, bool remove)
     217             :         __attribute__((__visibility__("hidden")));
     218             : void STRMPfree(BAT *b)
     219             :         __attribute__((__visibility__("hidden")));
     220             : void MT_init_posix(void)
     221             :         __attribute__((__visibility__("hidden")));
     222             : void *MT_mmap(const char *path, int mode, size_t len)
     223             :         __attribute__((__visibility__("hidden")));
     224             : void *MT_mremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     225             :         __attribute__((__visibility__("hidden")));
     226             : int MT_msync(void *p, size_t len)
     227             :         __attribute__((__visibility__("hidden")));
     228             : int MT_munmap(void *p, size_t len)
     229             :         __attribute__((__visibility__("hidden")));
     230             : void OIDXfree(BAT *b)
     231             :         __attribute__((__visibility__("hidden")));
     232             : void persistOIDX(BAT *b)
     233             :         __attribute__((__visibility__("hidden")));
     234             : void PROPdestroy(BAT *b)
     235             :         __attribute__((__visibility__("hidden")));
     236             : void PROPdestroy_nolock(BAT *b)
     237             :         __attribute__((__visibility__("hidden")));
     238             : void settailname(Heap *restrict tail, const char *restrict physnme, int tt, int width)
     239             :         __attribute__((__visibility__("hidden")));
     240             : void strCleanHash(Heap *hp, bool rebuild)
     241             :         __attribute__((__visibility__("hidden")));
     242             : gdk_return strHeap(Heap *d, size_t cap)
     243             :         __attribute__((__visibility__("hidden")));
     244             : var_t strLocate(Heap *h, const char *v)
     245             :         __attribute__((__visibility__("hidden")));
     246             : var_t strPut(BAT *b, var_t *dst, const void *v)
     247             :         __attribute__((__visibility__("hidden")));
     248             : char *strRead(str a, size_t *dstlen, stream *s, size_t cnt)
     249             :         __attribute__((__visibility__("hidden")));
     250             : ssize_t strToStr(char **restrict dst, size_t *restrict len, const char *restrict src, bool external)
     251             :         __attribute__((__visibility__("hidden")));
     252             : gdk_return strWrite(const char *a, stream *s, size_t cnt)
     253             :         __attribute__((__visibility__("hidden")));
     254             : gdk_return TMcommit(void)
     255             :         __attribute__((__visibility__("hidden")));
     256             : gdk_return unshare_varsized_heap(BAT *b)
     257             :         __attribute__((__warn_unused_result__))
     258             :         __attribute__((__visibility__("hidden")));
     259             : void VIEWdestroy(BAT *b)
     260             :         __attribute__((__visibility__("hidden")));
     261             : BAT *virtualize(BAT *bn)
     262             :         __attribute__((__visibility__("hidden")));
     263             : 
     264             : /* calculate the integer 2 logarithm (i.e. position of highest set
     265             :  * bit) of the argument (with a slight twist: 0 gives 0, 1 gives 1,
     266             :  * 0x8 to 0xF give 4, etc.) */
     267             : static inline unsigned
     268       10449 : ilog2(BUN x)
     269             : {
     270       10449 :         if (x == 0)
     271             :                 return 0;
     272             : #ifdef __has_builtin
     273             : #if SIZEOF_BUN == 8 && __has_builtin(__builtin_clzll)
     274       10445 :         return (unsigned) (64 - __builtin_clzll((unsigned long long) x));
     275             : #define BUILTIN_USED
     276             : #elif __has_builtin(__builtin_clz)
     277             :         return (unsigned) (32 - __builtin_clz((unsigned) x));
     278             : #define BUILTIN_USED
     279             : #endif
     280             : #endif
     281             : #ifndef BUILTIN_USED
     282             : #if defined(_MSC_VER)
     283             :         unsigned long n;
     284             :         if (
     285             : #if SIZEOF_BUN == 8
     286             :                 _BitScanReverse64(&n, (unsigned __int64) x)
     287             : #else
     288             :                 _BitScanReverse(&n, (unsigned long) x)
     289             : #endif
     290             :                 )
     291             :                 return (unsigned) n + 1;
     292             :         else
     293             :                 return 0;
     294             : #else
     295             :         unsigned n = 0;
     296             :         BUN y;
     297             : 
     298             :         /* use a "binary search" method */
     299             : #if SIZEOF_BUN == 8
     300             :         if ((y = x >> 32) != 0) {
     301             :                 x = y;
     302             :                 n += 32;
     303             :         }
     304             : #endif
     305             :         if ((y = x >> 16) != 0) {
     306             :                 x = y;
     307             :                 n += 16;
     308             :         }
     309             :         if ((y = x >> 8) != 0) {
     310             :                 x = y;
     311             :                 n += 8;
     312             :         }
     313             :         if ((y = x >> 4) != 0) {
     314             :                 x = y;
     315             :                 n += 4;
     316             :         }
     317             :         if ((y = x >> 2) != 0) {
     318             :                 x = y;
     319             :                 n += 2;
     320             :         }
     321             :         if ((y = x >> 1) != 0) {
     322             :                 x = y;
     323             :                 n += 1;
     324             :         }
     325             :         return n + (x != 0);
     326             : #endif
     327             : #endif
     328             : #undef BUILTIN_USED
     329             : }
     330             : 
     331             : /* some macros to help print info about BATs when using ALGODEBUG */
     332             : #define ALGOBATFMT      "%s#" BUNFMT "@" OIDFMT "[%s%s]%s%s%s%s%s%s%s%s%s"
     333             : #define ALGOBATPAR(b)                                                   \
     334             :         BATgetId(b),                                                    \
     335             :         BATcount(b),                                                    \
     336             :         b->hseqbase,                                                 \
     337             :         ATOMname(b->ttype),                                          \
     338             :         b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"", \
     339             :         !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T", \
     340             :         BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "", \
     341             :         b->tsorted ? "S" : b->tnosorted ? "!s" : "",                        \
     342             :         b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "",          \
     343             :         b->tkey ? "K" : b->tnokey[1] ? "!k" : "",                   \
     344             :         b->tnonil ? "N" : "",                                            \
     345             :         b->thash ? "H" : "",                                             \
     346             :         b->torderidx ? "O" : "",                                 \
     347             :         b->tstrimps ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->tstrimps ? "(I)" : ""
     348             : /* use ALGOOPTBAT* when BAT is optional (can be NULL) */
     349             : #define ALGOOPTBATFMT   "%s%s" BUNFMT "%s" OIDFMT "%s%s%s%s%s%s%s%s%s%s%s%s%s"
     350             : #define ALGOOPTBATPAR(b)                                                \
     351             :         b ? BATgetId(b) : "",                                         \
     352             :         b ? "#" : "",                                                       \
     353             :         b ? BATcount(b) : 0,                                            \
     354             :         b ? "@" : "",                                                       \
     355             :         b ? b->hseqbase : 0,                                         \
     356             :         b ? "[" : "",                                                       \
     357             :         b ? ATOMname(b->ttype) : "",                                       \
     358             :         b ? b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"" : "", \
     359             :         b ? "]" : "",                                                       \
     360             :         b ? !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T" : "", \
     361             :         b ? BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && b->tvheap && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "" : "", \
     362             :         b ? b->tsorted ? "S" : b->tnosorted ? "!s" : "" : "",             \
     363             :         b ? b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "" : "",       \
     364             :         b ? b->tkey ? "K" : b->tnokey[1] ? "!k" : "" : "",                \
     365             :         b && b->tnonil ? "N" : "",                                       \
     366             :         b && b->thash ? "H" : "",                                        \
     367             :         b && b->torderidx ? "O" : "",                                    \
     368             :         b ? b->tstrimps ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->tstrimps ? "(I)" : "" : ""
     369             : 
     370             : #ifdef __SANITIZE_THREAD__
     371             : #define BBP_BATMASK     31
     372             : #else
     373             : #define BBP_BATMASK     ((1 << (SIZEOF_SIZE_T + 5)) - 1)
     374             : #endif
     375             : 
     376             : struct PROPrec {
     377             :         enum prop_t id;
     378             :         ValRecord v;
     379             :         struct PROPrec *next;   /* simple chain of properties */
     380             : };
     381             : 
     382             : typedef uint64_t strimp_masks_t;  /* TODO: make this a sparse matrix */
     383             : 
     384             : struct Strimps {
     385             :         Heap strimps;
     386             :         uint8_t *sizes_base;    /* pointer into strimps heap (pair sizes)  */
     387             :         uint8_t *pairs_base;    /* pointer into strimps heap (pairs start)   */
     388             :         void *bitstrings_base;  /* pointer into strimps heap (bitstrings
     389             :                                  * start) bitstrings_base is a pointer
     390             :                                  * to uint64_t */
     391             :         size_t rec_cnt;         /* reconstruction counter: how many
     392             :                                  * bitstrings were added after header
     393             :                                  * construction. Currently unused. */
     394             :         strimp_masks_t *masks;  /* quick access to masks for
     395             :                                  * bitstring construction */
     396             : };
     397             : 
     398             : typedef struct {
     399             :         MT_Lock swap;
     400             : } batlock_t;
     401             : 
     402             : typedef char long_str[IDLENGTH];        /* standard GDK static string */
     403             : 
     404             : #define MAXFARMS       32
     405             : 
     406             : extern struct BBPfarm_t {
     407             :         uint32_t roles;         /* bitmask of allowed roles */
     408             :         const char *dirname;    /* farm directory */
     409             :         FILE *lock_file;
     410             : } BBPfarms[MAXFARMS];
     411             : 
     412             : extern batlock_t GDKbatLock[BBP_BATMASK + 1];
     413             : extern size_t GDK_mmap_minsize_persistent; /* size after which we use memory mapped files for persistent heaps */
     414             : extern size_t GDK_mmap_minsize_transient; /* size after which we use memory mapped files for transient heaps */
     415             : extern size_t GDK_mmap_pagesize; /* mmap granularity */
     416             : 
     417             : #define BATcheck(tst, err)                              \
     418             :         do {                                            \
     419             :                 if ((tst) == NULL) {                    \
     420             :                         GDKerror("BAT required.\n");  \
     421             :                         return (err);                   \
     422             :                 }                                       \
     423             :         } while (0)
     424             : #define ERRORcheck(tst, msg, err)               \
     425             :         do {                                    \
     426             :                 if (tst) {                      \
     427             :                         GDKerror(msg);          \
     428             :                         return (err);           \
     429             :                 }                               \
     430             :         } while (0)
     431             : 
     432             : #define GDKswapLock(x)  GDKbatLock[(x)&BBP_BATMASK].swap
     433             : 
     434             : #define HEAPREMOVE      ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 1))
     435             : #define DELAYEDREMOVE   ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2))
     436             : #define HEAPREFS        (((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2)) - 1)
     437             : 
     438             : /* when the number of updates to a BAT is less than 1 in this number, we
     439             :  * keep the unique_est property */
     440             : #define GDK_UNIQUE_ESTIMATE_KEEP_FRACTION       1000
     441             : extern BUN gdk_unique_estimate_keep_fraction; /* should become a define once */
     442             : /* if the number of unique values is less than 1 in this number, we
     443             :  * destroy the hash rather than update it in HASH{append,insert,delete} */
     444             : #define HASH_DESTROY_UNIQUES_FRACTION           1000
     445             : extern BUN hash_destroy_uniques_fraction;     /* likewise */
     446             : /* if the estimated number of unique values is less than 1 in this
     447             :  * number, don't build a hash table to do a hashselect */
     448             : #define NO_HASH_SELECT_FRACTION                 1000
     449             : extern dbl no_hash_select_fraction;           /* same here */
     450             : /* if the hash chain is longer than this number, we delete the hash
     451             :  * rather than maintaining it in HASHdelete */
     452             : #define HASH_DESTROY_CHAIN_LENGTH               1000
     453             : extern BUN hash_destroy_chain_length;
     454             : 
     455             : #if !defined(NDEBUG) && !defined(__COVERITY__)
     456             : /* see comment in gdk.h */
     457             : #ifdef __GNUC__
     458             : #define GDKmremap(p, m, oa, os, ns)                                     \
     459             :         ({                                                              \
     460             :                 const char *_path = (p);                                \
     461             :                 int _mode = (m);                                        \
     462             :                 void *_oa = (oa);                                       \
     463             :                 size_t _os = (os);                                      \
     464             :                 size_t *_ns = (ns);                                     \
     465             :                 size_t _ons = *_ns;                                     \
     466             :                 void *_res = GDKmremap(_path, _mode, _oa, _os, _ns);    \
     467             :                 TRC_DEBUG(ALLOC,                                        \
     468             :                           "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n", \
     469             :                           _path ? _path : "NULL", (unsigned) _mode,   \
     470             :                           _oa, _os, _ons, *_ns, _res);                  \
     471             :                 _res;                                                   \
     472             :          })
     473             : #else
     474             : static inline void *
     475             : GDKmremap_debug(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     476             : {
     477             :         size_t orig_new_size = *new_size;
     478             :         void *res = GDKmremap(path, mode, old_address, old_size, new_size);
     479             :         TRC_DEBUG(ALLOC, "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n",
     480             :                   path ? path : "NULL", (unsigned) mode,
     481             :                   old_address, old_size, orig_new_size, *new_size, res);
     482             :         return res;
     483             : }
     484             : #define GDKmremap(p, m, oa, os, ns)     GDKmremap_debug(p, m, oa, os, ns)
     485             : 
     486             : #endif
     487             : #endif

Generated by: LCOV version 1.14