~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to callgrind/costs.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-06-26 00:17:17 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20060626001717-qi51nzty57cb12q6
Tags: upstream-3.2.0
Import upstream version 3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*--------------------------------------------------------------------*/
 
2
/*--- Callgrind                                                    ---*/
 
3
/*---                                                   ct_costs.c ---*/
 
4
/*--------------------------------------------------------------------*/
 
5
 
 
6
/*
 
7
   This file is part of Callgrind, a Valgrind tool for call tracing.
 
8
 
 
9
   Copyright (C) 2002-2006, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
 
10
 
 
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.
 
15
 
 
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.
 
20
 
 
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.
 
25
 
 
26
   The GNU General Public License is contained in the file COPYING.
 
27
*/
 
28
 
 
29
#include "global.h"
 
30
 
 
31
#include <pub_tool_mallocfree.h>
 
32
 
 
33
#define COSTCHUNK_SIZE 100000
 
34
 
 
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;
 
39
 
 
40
ULong* CLG_(get_costarray)(Int size)
 
41
{
 
42
  ULong* ptr;
 
43
 
 
44
  if (!cost_chunk_current ||
 
45
      (cost_chunk_current->size - cost_chunk_current->used < size)) {
 
46
    CostChunk* cc  = (CostChunk*) CLG_MALLOC(sizeof(CostChunk) +
 
47
                                              COSTCHUNK_SIZE * sizeof(ULong));
 
48
    cc->size = COSTCHUNK_SIZE;
 
49
    cc->used = 0;
 
50
    cc->next = 0;
 
51
 
 
52
    if (cost_chunk_current)
 
53
      cost_chunk_current->next = cc;
 
54
    cost_chunk_current = cc;
 
55
 
 
56
    if (!cost_chunk_base) cost_chunk_base = cc;
 
57
 
 
58
    CLG_(costarray_chunks)++;
 
59
  }
 
60
  
 
61
  ptr = &(cost_chunk_current->data[cost_chunk_current->used]);
 
62
  cost_chunk_current->used += size;
 
63
 
 
64
  CLG_(costarray_entries) += size;
 
65
 
 
66
  return ptr;
 
67
}
 
68
 
 
69
void CLG_(free_costarrays)()
 
70
{
 
71
  CostChunk* cc = cost_chunk_base, *cc_next;
 
72
  while(cc) {
 
73
    cc_next = cc->next;
 
74
    VG_(free)(cc);
 
75
    cc = cc_next;
 
76
  }
 
77
  cost_chunk_base = 0;
 
78
  cost_chunk_current = 0;
 
79
}