LCOV - code coverage report
Current view: top level - gdk - gdk_private.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 6 100.0 %
Date: 2021-09-14 19:48:19 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.14