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-12-20 21:24:02 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             :         __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      856926 : HASHmask(BUN cnt)
     190             : {
     191      856926 :         cnt = cnt * 8 / 7;
     192      856926 :         if (cnt < BATTINY)
     193       37756 :                 cnt = BATTINY;
     194      606074 :         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             : void VIEWdestroy(BAT *b)
     264             :         __attribute__((__visibility__("hidden")));
     265             : BAT *virtualize(BAT *bn)
     266             :         __attribute__((__visibility__("hidden")));
     267             : 
     268             : /* calculate the integer 2 logarithm (i.e. position of highest set
     269             :  * bit) of the argument (with a slight twist: 0 gives 0, 1 gives 1,
     270             :  * 0x8 to 0xF give 4, etc.) */
     271             : __attribute__((__const__))
     272             : static inline unsigned
     273       13625 : ilog2(BUN x)
     274             : {
     275       13625 :         if (x == 0)
     276             :                 return 0;
     277             : #ifdef __has_builtin
     278             : #if SIZEOF_BUN == 8 && __has_builtin(__builtin_clzll)
     279       13617 :         return (unsigned) (64 - __builtin_clzll((unsigned long long) x));
     280             : #define BUILTIN_USED
     281             : #elif __has_builtin(__builtin_clz)
     282             :         return (unsigned) (32 - __builtin_clz((unsigned) x));
     283             : #define BUILTIN_USED
     284             : #endif
     285             : #endif
     286             : #ifndef BUILTIN_USED
     287             : #if defined(_MSC_VER)
     288             :         unsigned long n;
     289             :         if (
     290             : #if SIZEOF_BUN == 8
     291             :                 _BitScanReverse64(&n, (unsigned __int64) x)
     292             : #else
     293             :                 _BitScanReverse(&n, (unsigned long) x)
     294             : #endif
     295             :                 )
     296             :                 return (unsigned) n + 1;
     297             :         else
     298             :                 return 0;
     299             : #else
     300             :         unsigned n = 0;
     301             :         BUN y;
     302             : 
     303             :         /* use a "binary search" method */
     304             : #if SIZEOF_BUN == 8
     305             :         if ((y = x >> 32) != 0) {
     306             :                 x = y;
     307             :                 n += 32;
     308             :         }
     309             : #endif
     310             :         if ((y = x >> 16) != 0) {
     311             :                 x = y;
     312             :                 n += 16;
     313             :         }
     314             :         if ((y = x >> 8) != 0) {
     315             :                 x = y;
     316             :                 n += 8;
     317             :         }
     318             :         if ((y = x >> 4) != 0) {
     319             :                 x = y;
     320             :                 n += 4;
     321             :         }
     322             :         if ((y = x >> 2) != 0) {
     323             :                 x = y;
     324             :                 n += 2;
     325             :         }
     326             :         if ((y = x >> 1) != 0) {
     327             :                 x = y;
     328             :                 n += 1;
     329             :         }
     330             :         return n + (x != 0);
     331             : #endif
     332             : #endif
     333             : #undef BUILTIN_USED
     334             : }
     335             : 
     336             : /* some macros to help print info about BATs when using ALGODEBUG */
     337             : #define ALGOBATFMT      "%s#" BUNFMT "@" OIDFMT "[%s%s]%s%s%s%s%s%s%s%s%s"
     338             : #define ALGOBATPAR(b)                                                   \
     339             :         BATgetId(b),                                                    \
     340             :         BATcount(b),                                                    \
     341             :         b->hseqbase,                                                 \
     342             :         ATOMname(b->ttype),                                          \
     343             :         b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"", \
     344             :         !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T", \
     345             :         BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "", \
     346             :         b->tsorted ? "S" : b->tnosorted ? "!s" : "",                        \
     347             :         b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "",          \
     348             :         b->tkey ? "K" : b->tnokey[1] ? "!k" : "",                   \
     349             :         b->tnonil ? "N" : "",                                            \
     350             :         b->thash ? "H" : "",                                             \
     351             :         b->torderidx ? "O" : "",                                 \
     352             :         b->tstrimps ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->tstrimps ? "(I)" : ""
     353             : /* use ALGOOPTBAT* when BAT is optional (can be NULL) */
     354             : #define ALGOOPTBATFMT   "%s%s" BUNFMT "%s" OIDFMT "%s%s%s%s%s%s%s%s%s%s%s%s%s"
     355             : #define ALGOOPTBATPAR(b)                                                \
     356             :         b ? BATgetId(b) : "",                                         \
     357             :         b ? "#" : "",                                                       \
     358             :         b ? BATcount(b) : 0,                                            \
     359             :         b ? "@" : "",                                                       \
     360             :         b ? b->hseqbase : 0,                                         \
     361             :         b ? "[" : "",                                                       \
     362             :         b ? ATOMname(b->ttype) : "",                                       \
     363             :         b ? b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"" : "", \
     364             :         b ? "]" : "",                                                       \
     365             :         b ? !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T" : "", \
     366             :         b ? BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && b->tvheap && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "" : "", \
     367             :         b ? b->tsorted ? "S" : b->tnosorted ? "!s" : "" : "",             \
     368             :         b ? b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "" : "",       \
     369             :         b ? b->tkey ? "K" : b->tnokey[1] ? "!k" : "" : "",                \
     370             :         b && b->tnonil ? "N" : "",                                       \
     371             :         b && b->thash ? "H" : "",                                        \
     372             :         b && b->torderidx ? "O" : "",                                    \
     373             :         b ? b->tstrimps ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->tstrimps ? "(I)" : "" : ""
     374             : 
     375             : #ifdef __SANITIZE_THREAD__
     376             : #define BBP_BATMASK     31
     377             : #else
     378             : #define BBP_BATMASK     ((1 << (SIZEOF_SIZE_T + 5)) - 1)
     379             : #endif
     380             : 
     381             : struct PROPrec {
     382             :         enum prop_t id;
     383             :         ValRecord v;
     384             :         struct PROPrec *next;   /* simple chain of properties */
     385             : };
     386             : 
     387             : typedef uint64_t strimp_masks_t;  /* TODO: make this a sparse matrix */
     388             : 
     389             : struct Strimps {
     390             :         Heap strimps;
     391             :         uint8_t *sizes_base;    /* pointer into strimps heap (pair sizes)  */
     392             :         uint8_t *pairs_base;    /* pointer into strimps heap (pairs start)   */
     393             :         void *bitstrings_base;  /* pointer into strimps heap (bitstrings
     394             :                                  * start) bitstrings_base is a pointer
     395             :                                  * to uint64_t */
     396             :         size_t rec_cnt;         /* reconstruction counter: how many
     397             :                                  * bitstrings were added after header
     398             :                                  * construction. Currently unused. */
     399             :         strimp_masks_t *masks;  /* quick access to masks for
     400             :                                  * bitstring construction */
     401             : };
     402             : 
     403             : typedef struct {
     404             :         MT_Lock swap;
     405             : } batlock_t;
     406             : 
     407             : typedef char long_str[IDLENGTH];        /* standard GDK static string */
     408             : 
     409             : #define MAXFARMS       32
     410             : 
     411             : extern struct BBPfarm_t {
     412             :         uint32_t roles;         /* bitmask of allowed roles */
     413             :         const char *dirname;    /* farm directory */
     414             :         FILE *lock_file;
     415             : } BBPfarms[MAXFARMS];
     416             : 
     417             : extern batlock_t GDKbatLock[BBP_BATMASK + 1];
     418             : extern size_t GDK_mmap_minsize_persistent; /* size after which we use memory mapped files for persistent heaps */
     419             : extern size_t GDK_mmap_minsize_transient; /* size after which we use memory mapped files for transient heaps */
     420             : extern size_t GDK_mmap_pagesize; /* mmap granularity */
     421             : 
     422             : #define BATcheck(tst, err)                              \
     423             :         do {                                            \
     424             :                 if ((tst) == NULL) {                    \
     425             :                         GDKerror("BAT required.\n");  \
     426             :                         return (err);                   \
     427             :                 }                                       \
     428             :         } while (0)
     429             : #define ERRORcheck(tst, msg, err)               \
     430             :         do {                                    \
     431             :                 if (tst) {                      \
     432             :                         GDKerror(msg);          \
     433             :                         return (err);           \
     434             :                 }                               \
     435             :         } while (0)
     436             : 
     437             : #define GDKswapLock(x)  GDKbatLock[(x)&BBP_BATMASK].swap
     438             : 
     439             : #define HEAPREMOVE      ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 1))
     440             : #define DELAYEDREMOVE   ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2))
     441             : #define HEAPREFS        (((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2)) - 1)
     442             : 
     443             : /* when the number of updates to a BAT is less than 1 in this number, we
     444             :  * keep the unique_est property */
     445             : #define GDK_UNIQUE_ESTIMATE_KEEP_FRACTION       1000
     446             : extern BUN gdk_unique_estimate_keep_fraction; /* should become a define once */
     447             : /* if the number of unique values is less than 1 in this number, we
     448             :  * destroy the hash rather than update it in HASH{append,insert,delete} */
     449             : #define HASH_DESTROY_UNIQUES_FRACTION           1000
     450             : extern BUN hash_destroy_uniques_fraction;     /* likewise */
     451             : /* if the estimated number of unique values is less than 1 in this
     452             :  * number, don't build a hash table to do a hashselect */
     453             : #define NO_HASH_SELECT_FRACTION                 1000
     454             : extern dbl no_hash_select_fraction;           /* same here */
     455             : /* if the hash chain is longer than this number, we delete the hash
     456             :  * rather than maintaining it in HASHdelete */
     457             : #define HASH_DESTROY_CHAIN_LENGTH               1000
     458             : extern BUN hash_destroy_chain_length;
     459             : 
     460             : #if !defined(NDEBUG) && !defined(__COVERITY__)
     461             : /* see comment in gdk.h */
     462             : #ifdef __GNUC__
     463             : #define GDKmremap(p, m, oa, os, ns)                                     \
     464             :         ({                                                              \
     465             :                 const char *_path = (p);                                \
     466             :                 int _mode = (m);                                        \
     467             :                 void *_oa = (oa);                                       \
     468             :                 size_t _os = (os);                                      \
     469             :                 size_t *_ns = (ns);                                     \
     470             :                 size_t _ons = *_ns;                                     \
     471             :                 void *_res = GDKmremap(_path, _mode, _oa, _os, _ns);    \
     472             :                 TRC_DEBUG(ALLOC,                                        \
     473             :                           "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n", \
     474             :                           _path ? _path : "NULL", (unsigned) _mode,   \
     475             :                           _oa, _os, _ons, *_ns, _res);                  \
     476             :                 _res;                                                   \
     477             :          })
     478             : #else
     479             : static inline void *
     480             : GDKmremap_debug(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     481             : {
     482             :         size_t orig_new_size = *new_size;
     483             :         void *res = GDKmremap(path, mode, old_address, old_size, new_size);
     484             :         TRC_DEBUG(ALLOC, "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n",
     485             :                   path ? path : "NULL", (unsigned) mode,
     486             :                   old_address, old_size, orig_new_size, *new_size, res);
     487             :         return res;
     488             : }
     489             : #define GDKmremap(p, m, oa, os, ns)     GDKmremap_debug(p, m, oa, os, ns)
     490             : 
     491             : #endif
     492             : #endif

Generated by: LCOV version 1.14