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

Generated by: LCOV version 1.14