Commit 132a4d59 by Christian Kern

fixed code style issues, reported by cpplint

parent 053ca488
...@@ -79,7 +79,7 @@ namespace internal { ...@@ -79,7 +79,7 @@ namespace internal {
#endif #endif
template< typename GuardType > template< typename GuardType >
void HazardPointer< GuardType >::RemoveGuard(int guard_position){ void HazardPointer< GuardType >::RemoveGuard(int guard_position) {
const unsigned int my_thread_id = GetObjectLocalThreadIndex(); const unsigned int my_thread_id = GetObjectLocalThreadIndex();
// check invariants... // check invariants...
...@@ -240,15 +240,13 @@ namespace internal { ...@@ -240,15 +240,13 @@ namespace internal {
} }
} }
targetList[ii] = guardToCopy; targetList[ii] = guardToCopy;
} } else {
else {
// we copied the whole source list, remaining values in the target // we copied the whole source list, remaining values in the target
// have to be zeroed. // have to be zeroed.
if (targetList[ii] == undefinedGuard) { if (targetList[ii] == undefinedGuard) {
// end of target list // end of target list
break; break;
} } else {
else {
targetList[ii] = undefinedGuard; targetList[ii] = undefinedGuard;
} }
} }
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
// forward declaration for white-box test, used in friend declaration of // forward declaration for white-box test, used in friend declaration of
// HazardPointer class. // HazardPointer class.
namespace embb { namespace embb {
namespace containers{ namespace containers {
namespace test { namespace test {
class HazardPointerTest2; class HazardPointerTest2;
} }
...@@ -114,7 +114,6 @@ namespace internal { ...@@ -114,7 +114,6 @@ namespace internal {
template< typename GuardType > template< typename GuardType >
class HazardPointer { class HazardPointer {
public: public:
/** /**
* The user of the hazard pointer class has to provide the memory that is * The user of the hazard pointer class has to provide the memory that is
* managed here. The user has to take into account, that releasing of memory * managed here. The user has to take into account, that releasing of memory
......
...@@ -82,7 +82,7 @@ LockFreeMPMCQueue<Type, ValuePool>::LockFreeMPMCQueue(size_t capacity) : ...@@ -82,7 +82,7 @@ LockFreeMPMCQueue<Type, ValuePool>::LockFreeMPMCQueue(size_t capacity) :
// eligible for reuse. +1 for dummy node. // eligible for reuse. +1 for dummy node.
objectPool( objectPool(
MPMCQueueNodeHazardPointer_t::ComputeMaximumRetiredObjectCount(2) + MPMCQueueNodeHazardPointer_t::ComputeMaximumRetiredObjectCount(2) +
capacity + 1), capacity + 1),
// Disable "this is used in base member initializer" warning. // Disable "this is used in base member initializer" warning.
// We explicitly want this. // We explicitly want this.
#ifdef EMBB_PLATFORM_COMPILER_MSVC #ifdef EMBB_PLATFORM_COMPILER_MSVC
......
...@@ -86,8 +86,7 @@ capacity(capacity), ...@@ -86,8 +86,7 @@ capacity(capacity),
objectPool( objectPool(
StackNodeHazardPointer_t::ComputeMaximumRetiredObjectCount(1) + StackNodeHazardPointer_t::ComputeMaximumRetiredObjectCount(1) +
capacity), capacity),
hazardPointer(delete_pointer_callback, NULL, 1) hazardPointer(delete_pointer_callback, NULL, 1) {
{
} }
template< typename Type, typename ValuePool > template< typename Type, typename ValuePool >
......
...@@ -32,8 +32,7 @@ namespace embb { ...@@ -32,8 +32,7 @@ namespace embb {
namespace containers { namespace containers {
namespace test { namespace test {
IntObjectTestPool::IntObjectTestPool(unsigned int pool_size) : IntObjectTestPool::IntObjectTestPool(unsigned int pool_size) :
poolSize(pool_size) poolSize(pool_size) {
{
simplePoolObjects = static_cast<int*>( simplePoolObjects = static_cast<int*>(
embb::base::Allocation::Allocate(sizeof(int)*pool_size)); embb::base::Allocation::Allocate(sizeof(int)*pool_size));
...@@ -42,7 +41,7 @@ poolSize(pool_size) ...@@ -42,7 +41,7 @@ poolSize(pool_size)
pool_size)); pool_size));
for (unsigned int i = 0; i != pool_size; ++i) { for (unsigned int i = 0; i != pool_size; ++i) {
//in-place new for each array cell // in-place new for each array cell
new (&simplePool[i]) embb::base::Atomic<int>; new (&simplePool[i]) embb::base::Atomic<int>;
} }
...@@ -56,7 +55,7 @@ IntObjectTestPool::~IntObjectTestPool() { ...@@ -56,7 +55,7 @@ IntObjectTestPool::~IntObjectTestPool() {
embb::base::Allocation::Free(simplePoolObjects); embb::base::Allocation::Free(simplePoolObjects);
for (unsigned int i = 0; i != poolSize; ++i) { for (unsigned int i = 0; i != poolSize; ++i) {
//in-place new for each array cell // in-place new for each array cell
simplePool[i].~Atomic(); simplePool[i].~Atomic();
} }
...@@ -164,8 +163,8 @@ void HazardPointerTest::HazardPointerTest1ThreadMethod() { ...@@ -164,8 +163,8 @@ void HazardPointerTest::HazardPointerTest1ThreadMethod() {
== true == true
&& allocated_object_from_different_thread == allocated_object && allocated_object_from_different_thread == allocated_object
) { ) {
//try to make it probable to get an element from a different thread // try to make it probable to get an element from a different thread
//however, can be the same. Try 10000 times to get a different element. // however, can be the same. Try 10000 times to get a different element.
if (diff_count++ > 10000) { if (diff_count++ > 10000) {
same = true; same = true;
break; break;
...@@ -219,7 +218,7 @@ bool HazardPointerTest2::SetRelativeGuards() { ...@@ -219,7 +218,7 @@ bool HazardPointerTest2::SetRelativeGuards() {
unsigned int alreadyGuarded = 0; unsigned int alreadyGuarded = 0;
for (unsigned int i = my_begin; i != my_begin + guards_per_phread_count_; for (unsigned int i = my_begin; i != my_begin + guards_per_phread_count_;
++i){ ++i) {
if (shared_guarded_[i] != 0) { if (shared_guarded_[i] != 0) {
alreadyGuarded++; alreadyGuarded++;
guard_number++; guard_number++;
...@@ -234,8 +233,7 @@ bool HazardPointerTest2::SetRelativeGuards() { ...@@ -234,8 +233,7 @@ bool HazardPointerTest2::SetRelativeGuards() {
if (to_guard == shared_allocated_[i].Load()) { if (to_guard == shared_allocated_[i].Load()) {
// guard was successful. Communicate to other threads. // guard was successful. Communicate to other threads.
shared_guarded_[i] = to_guard; shared_guarded_[i] = to_guard;
} } else {
else {
// reset the guard, couldn't guard... // reset the guard, couldn't guard...
hazard_pointer_->RemoveGuard(guard_number); hazard_pointer_->RemoveGuard(guard_number);
} }
...@@ -284,7 +282,7 @@ void HazardPointerTest2::HazardPointerTest2Slave() { ...@@ -284,7 +282,7 @@ void HazardPointerTest2::HazardPointerTest2Slave() {
unsigned int thread_index; unsigned int thread_index;
embb_internal_thread_index(&thread_index); embb_internal_thread_index(&thread_index);
while (!SetRelativeGuards()) {}; while (!SetRelativeGuards()) {}
} }
void HazardPointerTest2::HazardPointerTest2Pre() { void HazardPointerTest2::HazardPointerTest2Pre() {
...@@ -305,24 +303,21 @@ void HazardPointerTest2::HazardPointerTest2Pre() { ...@@ -305,24 +303,21 @@ void HazardPointerTest2::HazardPointerTest2Pre() {
shared_guarded_ = static_cast<embb::base::Atomic<int*>*>( shared_guarded_ = static_cast<embb::base::Atomic<int*>*>(
embb::base::Allocation::Allocate(sizeof(embb::base::Atomic<int*>)* embb::base::Allocation::Allocate(sizeof(embb::base::Atomic<int*>)*
guaranteed_capacity_pool_) guaranteed_capacity_pool_));
);
for (unsigned int i = 0; i != for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) {
guaranteed_capacity_pool_; ++i) { // in-place new for each array cell
//in-place new for each array cell new (&shared_guarded_[i]) embb::base::Atomic < int* >;
new (&shared_guarded_[i]) embb::base::Atomic < int* > ;
} }
shared_allocated_ = static_cast<embb::base::Atomic<int*>*>( shared_allocated_ = static_cast<embb::base::Atomic<int*>*>(
embb::base::Allocation::Allocate(sizeof(embb::base::Atomic<int*>)* embb::base::Allocation::Allocate(sizeof(embb::base::Atomic<int*>)*
guaranteed_capacity_pool_) guaranteed_capacity_pool_));
);
for (unsigned int i = 0; i != for (unsigned int i = 0; i !=
guaranteed_capacity_pool_; ++i) { guaranteed_capacity_pool_; ++i) {
//in-place new for each array cell // in-place new for each array cell
new (&shared_allocated_[i]) embb::base::Atomic < int* > ; new (&shared_allocated_[i]) embb::base::Atomic < int* >;
} }
for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) { for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) {
...@@ -358,8 +353,7 @@ void HazardPointerTest2::HazardPointerTest2Post() { ...@@ -358,8 +353,7 @@ void HazardPointerTest2::HazardPointerTest2Post() {
hazard_pointer_->thread_local_retired_lists_ hazard_pointer_->thread_local_retired_lists_
[i2 + i*n_threads*guards_per_phread_count_] != [i2 + i*n_threads*guards_per_phread_count_] !=
hazard_pointer_->thread_local_retired_lists_ hazard_pointer_->thread_local_retired_lists_
[j2 + j*n_threads*guards_per_phread_count_] [j2 + j*n_threads*guards_per_phread_count_]);
);
checks++; checks++;
} }
...@@ -371,8 +365,7 @@ void HazardPointerTest2::HazardPointerTest2Post() { ...@@ -371,8 +365,7 @@ void HazardPointerTest2::HazardPointerTest2Post() {
PT_ASSERT( PT_ASSERT(
checks == checks ==
n_threads*n_threads*guards_per_phread_count_ * n_threads*n_threads*guards_per_phread_count_ *
(n_threads*n_threads*guards_per_phread_count_ - 1) (n_threads*n_threads*guards_per_phread_count_ - 1));
);
std::vector< int* > additionallyAllocated; std::vector< int* > additionallyAllocated;
...@@ -415,21 +408,20 @@ void HazardPointerTest2::HazardPointerTest2Post() { ...@@ -415,21 +408,20 @@ void HazardPointerTest2::HazardPointerTest2Post() {
PT_ASSERT( PT_ASSERT(
hazard_pointer_->thread_local_retired_lists_ hazard_pointer_->thread_local_retired_lists_
[i2 + i*n_threads*guards_per_phread_count_] != [i2 + i*n_threads*guards_per_phread_count_] !=
additionallyAllocated[a] additionallyAllocated[a]);
);
} }
} }
} }
for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) { for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) {
//in-place new for each array cell // in-place new for each array cell
shared_guarded_[i].~Atomic(); shared_guarded_[i].~Atomic();
} }
embb::base::Allocation::Free(shared_guarded_); embb::base::Allocation::Free(shared_guarded_);
for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) { for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) {
//in-place new for each array cell // in-place new for each array cell
shared_allocated_[i].~Atomic(); shared_allocated_[i].~Atomic();
} }
...@@ -463,8 +455,7 @@ void HazardPointerTest2::HazardPointerTest2ThreadMethod() { ...@@ -463,8 +455,7 @@ void HazardPointerTest2::HazardPointerTest2ThreadMethod() {
if (thread_index == current_master_) { if (thread_index == current_master_) {
HazardPointerTest2Master(); HazardPointerTest2Master();
} } else {
else {
HazardPointerTest2Slave(); HazardPointerTest2Slave();
} }
...@@ -476,7 +467,7 @@ void HazardPointerTest2::HazardPointerTest2ThreadMethod() { ...@@ -476,7 +467,7 @@ void HazardPointerTest2::HazardPointerTest2ThreadMethod() {
int desired = FINISH_MARKER; int desired = FINISH_MARKER;
// select thread, responsible for cleanup // select thread, responsible for cleanup
if (sync1_.CompareAndSwap(expected, desired)) { if (sync1_.CompareAndSwap(expected, desired)) {
//wipe arrays! // wipe arrays!
for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) { for (unsigned int i = 0; i != guaranteed_capacity_pool_; ++i) {
shared_guarded_[i] = 0; shared_guarded_[i] = 0;
shared_allocated_[i] = 0; shared_allocated_[i] = 0;
...@@ -508,9 +499,9 @@ n_threads(static_cast<int> ...@@ -508,9 +499,9 @@ n_threads(static_cast<int>
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4355) #pragma warning(disable:4355)
#endif #endif
delete_pointer_callback_( delete_pointer_callback_(
*this, *this,
&HazardPointerTest2::DeletePointerCallback) &HazardPointerTest2::DeletePointerCallback)
#ifdef EMBB_PLATFORM_COMPILER_MSVC #ifdef EMBB_PLATFORM_COMPILER_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif
...@@ -528,6 +519,6 @@ n_threads(static_cast<int> ...@@ -528,6 +519,6 @@ n_threads(static_cast<int>
this, static_cast<size_t>(n_threads)). this, static_cast<size_t>(n_threads)).
Post(&HazardPointerTest2::HazardPointerTest2Post, this); Post(&HazardPointerTest2::HazardPointerTest2Post, this);
} }
} // namespace test } // namespace test
} // namespace containers } // namespace containers
} // namespace embb } // namespace embb
\ No newline at end of file
...@@ -50,7 +50,7 @@ class IntObjectTestPool { ...@@ -50,7 +50,7 @@ class IntObjectTestPool {
static const int FREE_MARKER = 0; static const int FREE_MARKER = 0;
unsigned int poolSize; unsigned int poolSize;
IntObjectTestPool(unsigned int pool_size); explicit IntObjectTestPool(unsigned int pool_size);
~IntObjectTestPool(); ~IntObjectTestPool();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment