~ubuntu-branches/ubuntu/jaunty/google-perftools/jaunty

« back to all changes in this revision

Viewing changes to src/base/low_level_alloc.h

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2008-06-15 23:41:36 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20080615234136-al5gawvdvt5vhdtz
Tags: 0.98-1
* New upstream release. (Closes: #425147)
* Compiled with GCC 4.3. (Closes: #454841)
* debian/watch: can now report upstream's version (Closes: #450294)
* Because of a file conflict between tau and libgoogle-perftools the
  binary pprof is renamed as google-pprof. (Closes: #404001)
  Great thanks to Michael Mende.
* debian/rules: autoconf files are now generated at the build time.
* Bumped up Standards-Version to 3.7.3, no changes are required.
* Split a new package, libtcmallc_minimal0. The upstream supports
  this module for wider platforms. So I leave its architecture to be
  `any'.
* libgoogle-perftools0's architecture is now i386. The upstream
  supports this module for x86 and x86_64. However, x86_64 requires
  libunwind's development head, which Debian does not have yet.
* Removed an unnecessary patch, debian/patches/02_profiler.cc_alpha.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006, Google Inc.
 
2
 * All rights reserved.
 
3
 * 
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 * 
 
8
 *     * Redistributions of source code must retain the above copyright
 
9
 * notice, this list of conditions and the following disclaimer.
 
10
 *     * Redistributions in binary form must reproduce the above
 
11
 * copyright notice, this list of conditions and the following disclaimer
 
12
 * in the documentation and/or other materials provided with the
 
13
 * distribution.
 
14
 *     * Neither the name of Google Inc. nor the names of its
 
15
 * contributors may be used to endorse or promote products derived from
 
16
 * this software without specific prior written permission.
 
17
 * 
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
22
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
24
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 *
 
30
 * ---
 
31
 * Author: Mike Burrows
 
32
 */
 
33
 
 
34
#if !defined(_BASE_LOW_LEVEL_ALLOC_H_)
 
35
#define _BASE_LOW_LEVEL_ALLOC_H_
 
36
 
 
37
// A simple thread-safe memory allocator that does not depend on
 
38
// mutexes or thread-specific data.  It is intended to be used
 
39
// sparingly, and only when malloc() would introduce an unwanted
 
40
// dependency, such as inside the heap-checker.
 
41
 
 
42
#include "config.h"
 
43
#include <stddef.h>             // for size_t
 
44
#include "base/basictypes.h"
 
45
 
 
46
class LowLevelAlloc {
 
47
 public:
 
48
  struct Arena;       // an arena from which memory may be allocated
 
49
 
 
50
  // Returns a pointer to a block of at least "request" bytes
 
51
  // that have been newly allocated from the specific arena.
 
52
  // for Alloc() call the DefaultArena() is used.
 
53
  // Returns 0 if passed request==0.
 
54
  // Does not return 0 under other circumstances; it crashes if memory
 
55
  // is not available.
 
56
  static void *Alloc(size_t request)
 
57
    ATTRIBUTE_SECTION(malloc_hook);
 
58
  static void *AllocWithArena(size_t request, Arena *arena)
 
59
    ATTRIBUTE_SECTION(malloc_hook);
 
60
 
 
61
  // Deallocates a region of memory that was previously allocated with
 
62
  // Alloc().   Does nothing if passed 0.   "s" must be either 0,
 
63
  // or must have been returned from a call to Alloc() and not yet passed to
 
64
  // Free() since that call to Alloc().  The space is returned to the arena
 
65
  // from which it was allocated.
 
66
  static void Free(void *s) ATTRIBUTE_SECTION(malloc_hook);
 
67
 
 
68
    // ATTRIBUTE_SECTION(malloc_hook) for Alloc* and Free
 
69
    // are to put all callers of MallocHook::Invoke* in this module
 
70
    // into special section,
 
71
    // so that MallocHook::GetCallerStackTrace can function accurately.
 
72
 
 
73
  // Create a new arena.
 
74
  // The root metadata for the new arena is allocated in the
 
75
  // meta_data_arena; the DefaultArena() can be passed for meta_data_arena.
 
76
  // These values may be ored into flags:
 
77
  enum {
 
78
    // Calls to Alloc() and Free() will be reported
 
79
    // via the MallocHook interface.
 
80
    // The DefaultArena() has this flag on.
 
81
    // NewArena(flags, DefaultArena()) w/o this bit in 'flags',
 
82
    // on the other hand, will not cause any MallocHook
 
83
    // calls even during the NewArena call itself
 
84
    // (it will in fact use meta_data_arena different from DefaultArena()).
 
85
    kCallMallocHook = 0x0001
 
86
  };
 
87
  static Arena *NewArena(int32 flags, Arena *meta_data_arena);
 
88
 
 
89
  // Destroys an arena allocated by NewArena and returns true,
 
90
  // provided no allocated blocks remain in the arena.
 
91
  // If allocated blocks remain in the arena, does nothing and
 
92
  // returns false.
 
93
  // It is illegal to attempt to destroy the DefaultArena().
 
94
  static bool DeleteArena(Arena *arena);
 
95
 
 
96
  // The default arena that always exists.
 
97
  static Arena *DefaultArena();
 
98
 
 
99
 private:
 
100
  LowLevelAlloc();      // no instances
 
101
};
 
102
 
 
103
#endif