A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
RefCountedObject.cc
Go to the documentation of this file.
1
/*****************************************************************************
2
* *
3
* Copyright 2018 Rice University *
4
* *
5
* Licensed under the Apache License, Version 2.0 (the "License"); *
6
* you may not use this file except in compliance with the License. *
7
* You may obtain a copy of the License at *
8
* *
9
* http://www.apache.org/licenses/LICENSE-2.0 *
10
* *
11
* Unless required by applicable law or agreed to in writing, software *
12
* distributed under the License is distributed on an "AS IS" BASIS, *
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14
* See the License for the specific language governing permissions and *
15
* limitations under the License. *
16
* *
17
*****************************************************************************/
18
19
#ifndef REF_COUNTED_OBJECT_CC
20
#define REF_COUNTED_OBJECT_CC
21
22
#include <cstddef>
23
#include <iostream>
24
#include <vector>
25
#include <algorithm>
26
#include <iterator>
27
#include <climits>
28
#include <cstring>
29
30
#include "
Allocator.h
"
31
#include "
RefCountedObject.h
"
32
#include "
RefCountMacros.h
"
33
34
namespace
pdb {
35
36
template
<
class
ObjType>
37
void
RefCountedObject<ObjType>::setRefCount
(
unsigned
toMe) {
38
39
// don't change the ref count for an un-managed object
40
if
(!
getAllocator
().isManaged(
this
)) {
41
return
;
42
}
43
44
NUM_COPIES
= toMe;
45
}
46
47
template
<
class
ObjType>
48
unsigned
RefCountedObject<ObjType>::getRefCount
() {
49
50
// an un-managed ref count is always huge
51
if
(!
getAllocator
().isManaged(
this
)) {
52
return
UINT_MAX;
53
}
54
55
return
NUM_COPIES
;
56
}
57
58
template
<
class
ObjType>
59
void
RefCountedObject<ObjType>::incRefCount
() {
60
61
// don't change the ref count for an un-managed object
62
if
(!
getAllocator
().isManaged(
this
)) {
63
return
;
64
}
65
66
NUM_COPIES
++;
67
}
68
69
// remember the ref count
70
template
<
class
ObjType>
71
void
RefCountedObject<ObjType>::decRefCount
(
PDBTemplateBase
& typeInfo) {
72
73
// don't change the ref count for an un-managed object
74
if
(!
getAllocator
().isManaged(
this
)) {
75
return
;
76
}
77
78
NUM_COPIES
--;
79
80
// if the ref count goes to zero, free the pointed-to object
81
if
(
NUM_COPIES
== 0) {
82
if
(typeInfo.
getTypeCode
() == 0) {
83
PDB_COUT
<<
"RefCountedObject::decRefCount: typeInfo=0 before deleteConstituentObject"
84
<< std::endl;
85
}
86
// call the appropriate delete to recursively free, if needed
87
typeInfo.
deleteConstituentObject
(getObject());
88
89
// and free the RAM
90
#ifdef DEBUG_OBJECT_MODEL
91
getAllocator
().
freeRAM
(
CHAR_PTR
(
this
), typeInfo.
getTypeCode
());
92
#else
93
getAllocator
().
freeRAM
(
CHAR_PTR
(
this
));
94
#endif
95
}
96
}
97
98
template
<
class
ObjType>
99
ObjType*
RefCountedObject<ObjType>::getObject
()
const
{
100
return
(ObjType*)(
CHAR_PTR
(
this
) +
REF_COUNT_PREAMBLE_SIZE
);
101
}
102
}
103
104
#endif
RefCountedObject.h
REF_COUNT_PREAMBLE_SIZE
#define REF_COUNT_PREAMBLE_SIZE
Definition:
RefCountMacros.h:23
pdb::PDBTemplateBase::deleteConstituentObject
void deleteConstituentObject(void *deleteMe) const
Allocator.h
pdb::RefCountedObject::incRefCount
void incRefCount()
Definition:
RefCountedObject.cc:59
pdb::getAllocator
Allocator & getAllocator()
Definition:
Allocator.cc:943
pdb::RefCountedObject::decRefCount
void decRefCount(PDBTemplateBase &typeInfo)
Definition:
RefCountedObject.cc:71
NUM_COPIES
#define NUM_COPIES
Definition:
RefCountMacros.h:26
CHAR_PTR
#define CHAR_PTR(c)
Definition:
Allocator.cc:33
RefCountMacros.h
pdb::PDBTemplateBase::getTypeCode
int16_t getTypeCode() const
PDB_COUT
#define PDB_COUT
Definition:
PDBDebug.h:31
pdb::RefCountedObject::getRefCount
unsigned getRefCount()
Definition:
RefCountedObject.cc:48
pdb::PDBTemplateBase
Definition:
PDBTemplateBase.h:37
pdb::RefCountedObject::getObject
ObjType * getObject() const
Definition:
RefCountedObject.cc:99
pdb::RefCountedObject::setRefCount
void setRefCount(unsigned toMe)
Definition:
RefCountedObject.cc:37
pdb::MultiPolicyAllocator::freeRAM
void freeRAM(void *here)
Definition:
Allocator.cc:632
plinycompute
pdb
src
objectModel
headers
RefCountedObject.cc
Generated on Mon Jun 18 2018 18:10:36 by
1.8.6