LCOV - code coverage report
Current view: top level - sql/storage/bat - bat_utils.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 50 67 74.6 %
Date: 2024-04-26 00:35:57 Functions: 11 13 84.6 %

          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             : #include "monetdb_config.h"
      14             : #include "bat_utils.h"
      15             : 
      16             : int
      17           0 : bat_fix(BAT *b)
      18             : {
      19           0 :         if (b)
      20           0 :                 return BBPfix(b->batCacheid);
      21             :         return 0;
      22             : }
      23             : 
      24             : void
      25    54449194 : bat_destroy(BAT *b)
      26             : {
      27    54449194 :         BBPreclaim(b);
      28    54491272 : }
      29             : 
      30             : BAT *
      31      310861 : bat_new(int tt, BUN size, role_t role)
      32             : {
      33      310861 :         BAT *bn = COLnew(0, tt, size, role);
      34      310904 :         if (bn)
      35      310904 :                 BBP_pid(bn->batCacheid) = 0;
      36      310904 :         return bn;
      37             : }
      38             : 
      39             : void
      40           0 : bat_clear(BAT *b)
      41             : {
      42           0 :         bat_set_access(b,BAT_WRITE);
      43           0 :         BATclear(b,true);
      44           0 :         bat_set_access(b,BAT_READ);
      45           0 : }
      46             : 
      47             : BAT *
      48    42751219 : temp_descriptor(log_bid b)
      49             : {
      50    42751219 :         return BATdescriptor((bat) b);
      51             : }
      52             : 
      53             : BAT *
      54      431357 : quick_descriptor(log_bid b)
      55             : {
      56      431357 :         return BBPquickdesc((bat) b);
      57             : }
      58             : 
      59             : void
      60      990707 : temp_destroy(log_bid b)
      61             : {
      62      990707 :         if (b)
      63      990809 :                 BBPrelease(b);
      64      991453 : }
      65             : 
      66             : log_bid
      67     1813573 : temp_dup(log_bid b)
      68             : {
      69     1813573 :         if (b)
      70     1813854 :                 BBPretain(b);
      71     1819534 :         return b;
      72             : }
      73             : 
      74             : log_bid
      75     1651937 : temp_create(BAT *b)
      76             : {
      77     1651937 :         temp_dup(b->batCacheid);
      78     1656631 :         return b->batCacheid;
      79             : }
      80             : 
      81             : log_bid
      82      156421 : temp_copy(log_bid b, bool renew, bool temp)
      83             : {
      84             :         /* make a copy of b, if temp is set only create a empty bat */
      85      156421 :         BAT *o, *c = NULL;
      86      156421 :         log_bid r;
      87             : 
      88      156421 :         if (!renew) {
      89           0 :                 if (!(o = temp_descriptor(b)))
      90             :                         return BID_NIL;
      91           0 :                 c = COLcopy(o, o->ttype, true, PERSISTENT);
      92           0 :                 bat_destroy(o);
      93           0 :                 if (!c)
      94             :                         return BID_NIL;
      95           0 :                 BATcommit(c, BUN_NONE);
      96             :         } else {
      97      156421 :                 if (!(o = quick_descriptor(b)))
      98             :                         return BID_NIL;
      99      156346 :                 if (!(c = bat_new(o->ttype, COLSIZE, PERSISTENT)))
     100             :                         return BID_NIL;
     101             :         }
     102      156347 :         if (!temp)
     103      155569 :                 bat_set_access(c, BAT_READ);
     104      156347 :         r = temp_create(c);
     105      156414 :         bat_destroy(c);
     106      156414 :         return r;
     107             : }
     108             : 
     109             : BAT *ebats[MAXATOMS] = { NULL };
     110             : 
     111             : log_bid
     112     1339821 : e_bat(int type)
     113             : {
     114     1339821 :         if (ebats[type] == NULL &&
     115           0 :             (ebats[type] = bat_new(type, 0, SYSTRANS)) == NULL)
     116             :                 return BID_NIL;
     117     1339821 :         return temp_create(ebats[type]);
     118             : }
     119             : 
     120             : BAT *
     121    13925638 : e_BAT(int type)
     122             : {
     123    13925638 :         if (ebats[type] == NULL &&
     124           0 :             (ebats[type] = bat_new(type, 0, SYSTRANS)) == NULL)
     125             :                 return NULL;
     126    13925638 :         return temp_descriptor(ebats[type]->batCacheid);
     127             : }
     128             : 
     129             : int
     130         341 : bat_utils_init(void)
     131             : {
     132         341 :         int t;
     133         341 :         char name[32];
     134             : 
     135       10194 :         for (t=1; t<GDKatomcnt; t++) {
     136        9853 :                 if (BATatoms[t].name[0]) {
     137        9853 :                         ebats[t] = bat_new(t, 0, SYSTRANS);
     138        9853 :                         if(ebats[t] == NULL) {
     139           0 :                                 for (t = t - 1; t >= 1; t--)
     140           0 :                                         bat_destroy(ebats[t]);
     141             :                                 return -1;
     142             :                         }
     143        9853 :                         bat_set_access(ebats[t], BAT_READ);
     144             :                         /* give it a name for debugging purposes */
     145        9853 :                         snprintf(name, sizeof(name), "sql_empty_%s_bat",
     146             :                                  ATOMname(t));
     147        9853 :                         BBPrename(ebats[t], name);
     148             :                 }
     149             :         }
     150             :         return 0;
     151             : }

Generated by: LCOV version 1.14