Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
object-pool.h
Go to the documentation of this file.
1
// Copyright 2012 Cloudera Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
16
#ifndef IMPALA_COMMON_OBJECT_POOL_H
17
#define IMPALA_COMMON_OBJECT_POOL_H
18
19
#include <vector>
20
#include <boost/thread/locks.hpp>
21
#include <boost/thread/mutex.hpp>
22
23
#include "
util/spinlock.h
"
24
25
namespace
impala {
26
30
class
ObjectPool
{
31
public
:
32
ObjectPool
():
objects_
() {}
33
34
~ObjectPool
() {
35
for
(ElementVector::iterator i =
objects_
.begin();
36
i !=
objects_
.end(); ++i) {
37
delete
*i;
38
}
39
}
40
41
template
<
class
T>
42
T*
Add
(T* t) {
45
SpecificElement<T>
* obj =
new
SpecificElement<T>
(t);
46
boost::lock_guard<SpinLock> l(
lock_
);
47
objects_
.push_back(obj);
48
return
t;
49
}
50
51
private
:
52
struct
GenericElement
{
53
virtual
~GenericElement
() {}
54
};
55
56
template
<
class
T>
57
struct
SpecificElement
:
GenericElement
{
58
SpecificElement
(T*
t
): t(t) {}
59
~SpecificElement
() {
60
delete
t
;
61
}
62
63
T*
t
;
64
};
65
66
typedef
std::vector<GenericElement*>
ElementVector
;
67
ElementVector
objects_
;
68
SpinLock
lock_
;
69
};
70
71
}
72
73
#endif
impala::ObjectPool::GenericElement::~GenericElement
virtual ~GenericElement()
Definition:
object-pool.h:53
impala::SpinLock
Lightweight spinlock.
Definition:
spinlock.h:24
spinlock.h
impala::ObjectPool
Definition:
object-pool.h:30
impala::ObjectPool::~ObjectPool
~ObjectPool()
Definition:
object-pool.h:34
impala::ObjectPool::objects_
ElementVector objects_
Definition:
object-pool.h:67
impala::ObjectPool::ElementVector
std::vector< GenericElement * > ElementVector
Definition:
object-pool.h:66
impala::ObjectPool::SpecificElement::SpecificElement
SpecificElement(T *t)
Definition:
object-pool.h:58
impala::ObjectPool::GenericElement
Definition:
object-pool.h:52
impala::ObjectPool::SpecificElement::~SpecificElement
~SpecificElement()
Definition:
object-pool.h:59
impala::ObjectPool::lock_
SpinLock lock_
Definition:
object-pool.h:68
impala::ObjectPool::SpecificElement::t
T * t
Definition:
object-pool.h:63
impala::ObjectPool::Add
T * Add(T *t)
Definition:
object-pool.h:42
impala::ObjectPool::ObjectPool
ObjectPool()
Definition:
object-pool.h:32
impala::ObjectPool::SpecificElement
Definition:
object-pool.h:57
be
src
common
object-pool.h
Generated on Thu May 7 2015 16:10:34 for Impala by
1.8.6