~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/Support/Recycler.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//==- llvm/Support/Recycler.h - Recycling Allocator --------------*- C++ -*-==//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This file defines the Recycler class template.  See the doxygen comment for
 
11
// Recycler for more details.
 
12
//
 
13
//===----------------------------------------------------------------------===//
 
14
 
 
15
#ifndef LLVM_SUPPORT_RECYCLER_H
 
16
#define LLVM_SUPPORT_RECYCLER_H
 
17
 
 
18
#include "llvm/ADT/ilist.h"
 
19
#include "llvm/Support/AlignOf.h"
 
20
#include <cassert>
 
21
 
 
22
namespace llvm {
 
23
 
 
24
/// PrintRecyclingAllocatorStats - Helper for RecyclingAllocator for
 
25
/// printing statistics.
 
26
///
 
27
void PrintRecyclerStats(size_t Size, size_t Align, size_t FreeListSize);
 
28
 
 
29
/// RecyclerStruct - Implementation detail for Recycler. This is a
 
30
/// class that the recycler imposes on free'd memory to carve out
 
31
/// next/prev pointers.
 
32
struct RecyclerStruct {
 
33
  RecyclerStruct *Prev, *Next;
 
34
};
 
35
 
 
36
template<>
 
37
struct ilist_traits<RecyclerStruct> :
 
38
    public ilist_default_traits<RecyclerStruct> {
 
39
  static RecyclerStruct *getPrev(const RecyclerStruct *t) { return t->Prev; }
 
40
  static RecyclerStruct *getNext(const RecyclerStruct *t) { return t->Next; }
 
41
  static void setPrev(RecyclerStruct *t, RecyclerStruct *p) { t->Prev = p; }
 
42
  static void setNext(RecyclerStruct *t, RecyclerStruct *n) { t->Next = n; }
 
43
 
 
44
  mutable RecyclerStruct Sentinel;
 
45
  RecyclerStruct *createSentinel() const {
 
46
    return &Sentinel;
 
47
  }
 
48
  static void destroySentinel(RecyclerStruct *) {}
 
49
 
 
50
  RecyclerStruct *provideInitialHead() const { return createSentinel(); }
 
51
  RecyclerStruct *ensureHead(RecyclerStruct*) const { return createSentinel(); }
 
52
  static void noteHead(RecyclerStruct*, RecyclerStruct*) {}
 
53
 
 
54
  static void deleteNode(RecyclerStruct *) {
 
55
    assert(0 && "Recycler's ilist_traits shouldn't see a deleteNode call!");
 
56
  }
 
57
};
 
58
 
 
59
/// Recycler - This class manages a linked-list of deallocated nodes
 
60
/// and facilitates reusing deallocated memory in place of allocating
 
61
/// new memory.
 
62
///
 
63
template<class T, size_t Size = sizeof(T), size_t Align = AlignOf<T>::Alignment>
 
64
class Recycler {
 
65
  /// FreeList - Doubly-linked list of nodes that have deleted contents and
 
66
  /// are not in active use.
 
67
  ///
 
68
  iplist<RecyclerStruct> FreeList;
 
69
 
 
70
public:
 
71
  ~Recycler() {
 
72
    // If this fails, either the callee has lost track of some allocation,
 
73
    // or the callee isn't tracking allocations and should just call
 
74
    // clear() before deleting the Recycler.
 
75
    assert(FreeList.empty() && "Non-empty recycler deleted!");
 
76
  }
 
77
 
 
78
  /// clear - Release all the tracked allocations to the allocator. The
 
79
  /// recycler must be free of any tracked allocations before being
 
80
  /// deleted; calling clear is one way to ensure this.
 
81
  template<class AllocatorType>
 
82
  void clear(AllocatorType &Allocator) {
 
83
    while (!FreeList.empty()) {
 
84
      T *t = reinterpret_cast<T *>(FreeList.remove(FreeList.begin()));
 
85
      Allocator.Deallocate(t);
 
86
    }
 
87
  }
 
88
 
 
89
  template<class SubClass, class AllocatorType>
 
90
  SubClass *Allocate(AllocatorType &Allocator) {
 
91
    assert(sizeof(SubClass) <= Size &&
 
92
           "Recycler allocation size is less than object size!");
 
93
    assert(AlignOf<SubClass>::Alignment <= Align &&
 
94
           "Recycler allocation alignment is less than object alignment!");
 
95
    return !FreeList.empty() ?
 
96
           reinterpret_cast<SubClass *>(FreeList.remove(FreeList.begin())) :
 
97
           static_cast<SubClass *>(Allocator.Allocate(Size, Align));
 
98
  }
 
99
 
 
100
  template<class AllocatorType>
 
101
  T *Allocate(AllocatorType &Allocator) {
 
102
    return Allocate<T>(Allocator);
 
103
  }
 
104
 
 
105
  template<class SubClass, class AllocatorType>
 
106
  void Deallocate(AllocatorType & /*Allocator*/, SubClass* Element) {
 
107
    FreeList.push_front(reinterpret_cast<RecyclerStruct *>(Element));
 
108
  }
 
109
 
 
110
  void PrintStats() {
 
111
    PrintRecyclerStats(Size, Align, FreeList.size());
 
112
  }
 
113
};
 
114
 
 
115
}
 
116
 
 
117
#endif