tests/vg_regtest: Always evaluate prerequisite expressions with sh
[valgrind.git] / callgrind / costs.c
blob63256c71cd79c40f3588b2881edc1d0b4caab441
1 /*--------------------------------------------------------------------*/
2 /*--- Callgrind ---*/
3 /*--- ct_costs.c ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Callgrind, a Valgrind tool for call tracing.
9 Copyright (C) 2002-2013, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 02111-1307, USA.
26 The GNU General Public License is contained in the file COPYING.
29 #include "global.h"
31 #include "pub_tool_mallocfree.h"
33 #define COSTCHUNK_SIZE 100000
35 UInt CLG_(costarray_entries) = 0;
36 UInt CLG_(costarray_chunks) = 0;
37 static CostChunk* cost_chunk_base = 0;
38 static CostChunk* cost_chunk_current = 0;
40 ULong* CLG_(get_costarray)(Int size)
42 ULong* ptr;
44 if (!cost_chunk_current ||
45 (cost_chunk_current->size - cost_chunk_current->used < size)) {
46 CostChunk* cc = (CostChunk*) CLG_MALLOC("cl.costs.gc.1",
47 sizeof(CostChunk) +
48 COSTCHUNK_SIZE * sizeof(ULong));
49 CLG_ASSERT(size < COSTCHUNK_SIZE);
51 cc->size = COSTCHUNK_SIZE;
52 cc->used = 0;
53 cc->next = 0;
55 if (cost_chunk_current)
56 cost_chunk_current->next = cc;
57 cost_chunk_current = cc;
59 if (!cost_chunk_base) cost_chunk_base = cc;
61 CLG_(costarray_chunks)++;
64 ptr = &(cost_chunk_current->data[cost_chunk_current->used]);
65 cost_chunk_current->used += size;
67 CLG_(costarray_entries) += size;
69 return ptr;