Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 13ef502

Browse files
Revert LockFreeArray changes
1 parent 44df169 commit 13ef502

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

cmake/Dependencies.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ find_package(TBB REQUIRED)
2626
include_directories(SYSTEM ${TBB_INCLUDE_DIRS})
2727
list(APPEND Peloton_LINKER_LIBS ${TBB_LIBRARIES})
2828

29-
#add_executable(TBB_Sample TBB_Sample.cpp)
30-
3129
# ---[ Cap'nProto
3230
include("cmake/External/capnproto.cmake")
3331
include_directories(SYSTEM ${CAPNP_INCLUDE_DIRS})

src/common/container/lock_free_array.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,41 @@ class IndirectionArray;
3131

3232
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
3333
LOCK_FREE_ARRAY_TYPE::LockFreeArray(){
34-
new_lock_free_array.clear();
34+
lock_free_array.reset(new lock_free_array_t());
3535
}
3636

3737
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
3838
LOCK_FREE_ARRAY_TYPE::~LockFreeArray(){
39-
new_lock_free_array.clear();
4039
}
4140

4241
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
4342
bool LOCK_FREE_ARRAY_TYPE::Update(const std::size_t &offset, ValueType value){
4443
PL_ASSERT(offset <= LOCK_FREE_ARRAY_MAX_SIZE);
4544
LOG_TRACE("Update at %lu", lock_free_array_offset.load());
46-
if (new_lock_free_array.size() < offset + 1) {
47-
new_lock_free_array.resize(LOCK_FREE_ARRAY_MAX_SIZE);
48-
}
49-
new_lock_free_array.at(offset) = value;
45+
lock_free_array->at(offset) = value;
5046
return true;
5147
}
5248

5349
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
5450
bool LOCK_FREE_ARRAY_TYPE::Append(ValueType value){
5551
LOG_TRACE("Appended at %lu", lock_free_array_offset.load());
56-
new_lock_free_array.push_back(value);
52+
lock_free_array->at(lock_free_array_offset++) = value;
5753
return true;
5854
}
5955

6056
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
6157
bool LOCK_FREE_ARRAY_TYPE::Erase(const std::size_t &offset, const ValueType& invalid_value){
6258
PL_ASSERT(offset <= LOCK_FREE_ARRAY_MAX_SIZE);
6359
LOG_TRACE("Erase at %lu", offset);
64-
new_lock_free_array.at(offset) = invalid_value;
60+
lock_free_array->at(offset) = invalid_value;
6561
return true;
6662
}
6763

6864
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
6965
ValueType LOCK_FREE_ARRAY_TYPE::Find(const std::size_t &offset) const{
7066
PL_ASSERT(offset <= LOCK_FREE_ARRAY_MAX_SIZE);
7167
LOG_TRACE("Find at %lu", offset);
72-
// auto value = lock_free_array->at(offset);
73-
auto value = new_lock_free_array.at(offset);
68+
auto value = lock_free_array->at(offset);
7469
return value;
7570
}
7671

@@ -82,11 +77,11 @@ ValueType LOCK_FREE_ARRAY_TYPE::FindValid(const std::size_t &offset,
8277

8378
std::size_t valid_array_itr = 0;
8479
std::size_t array_itr;
85-
auto new_lock_free_array_offset = new_lock_free_array.size();
80+
8681
for(array_itr = 0;
87-
array_itr < new_lock_free_array_offset;
82+
array_itr < lock_free_array_offset;
8883
array_itr++){
89-
auto value = new_lock_free_array.at(array_itr);
84+
auto value = lock_free_array->at(array_itr);
9085
if (value != invalid_value) {
9186
// Check offset
9287
if(valid_array_itr == offset) {
@@ -103,26 +98,22 @@ ValueType LOCK_FREE_ARRAY_TYPE::FindValid(const std::size_t &offset,
10398

10499
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
105100
size_t LOCK_FREE_ARRAY_TYPE::GetSize() const{
106-
return new_lock_free_array.size();
107-
// return lock_free_array_offset;
101+
return lock_free_array_offset;
108102
}
109103

110104
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
111105
bool LOCK_FREE_ARRAY_TYPE::IsEmpty() const{
112-
return new_lock_free_array.empty();
113-
// return lock_free_array->empty();
106+
return lock_free_array->empty();
114107
}
115108

116109
LOCK_FREE_ARRAY_TEMPLATE_ARGUMENTS
117110
void LOCK_FREE_ARRAY_TYPE::Clear(const ValueType& invalid_value) {
118111

119112
// Set invalid value for all elements and reset lock_free_array_offset
120-
121113
for(std::size_t array_itr = 0;
122-
array_itr < new_lock_free_array.size();
114+
array_itr < lock_free_array_offset;
123115
array_itr++){
124-
// lock_free_array->at(array_itr) = invalid_value;
125-
new_lock_free_array.at(array_itr) = invalid_value;
116+
lock_free_array->at(array_itr) = invalid_value;
126117
}
127118

128119
// Reset sentinel
@@ -136,9 +127,9 @@ bool LOCK_FREE_ARRAY_TYPE::Contains(const ValueType& value) {
136127
bool exists = false;
137128

138129
for(std::size_t array_itr = 0;
139-
array_itr < new_lock_free_array.size();
130+
array_itr < lock_free_array_offset;
140131
array_itr++){
141-
auto array_value = new_lock_free_array.at(array_itr);
132+
auto array_value = lock_free_array->at(array_itr);
142133
// Check array value
143134
if(array_value == value) {
144135
exists = true;

src/include/common/container/lock_free_array.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212

1313

1414
#pragma once
15-
#include "tbb/concurrent_vector.h"
16-
#include "tbb/tbb_allocator.h"
15+
1716
#include <cstdlib>
1817
#include <cstring>
1918
#include <cstdio>
2019
#include <array>
2120
#include <atomic>
2221
#include <memory>
2322

24-
25-
2623
namespace peloton {
2724

2825
#define LOCK_FREE_ARRAY_MAX_SIZE 1024 * 1024
@@ -75,10 +72,7 @@ class LockFreeArray {
7572
std::atomic<std::size_t> lock_free_array_offset {0};
7673

7774
// lock free array
78-
// std::unique_ptr<lock_free_array_t> lock_free_array;
79-
typedef tbb::concurrent_vector<ValueType, tbb::zero_allocator<ValueType>> TBBLockFreeArray;
80-
TBBLockFreeArray new_lock_free_array;
81-
75+
std::unique_ptr<lock_free_array_t> lock_free_array;
8276
};
8377

8478
} // namespace peloton

0 commit comments

Comments
 (0)