Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
preshing committed Feb 6, 2016
1 parent 4249e1a commit e8d98a0
Show file tree
Hide file tree
Showing 36 changed files with 518 additions and 457 deletions.
1 change: 1 addition & 0 deletions .clang-format
Expand Up @@ -7,3 +7,4 @@ DerivePointerAlignment: false
PointerAlignment: Left
SpaceAfterCStyleCast: true
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: true
2 changes: 1 addition & 1 deletion junction/ConcurrentMap_Grampa.cpp
Expand Up @@ -13,7 +13,7 @@
#include <junction/ConcurrentMap_Grampa.h>

namespace junction {

TURF_TRACE_DEFINE_BEGIN(ConcurrentMap_Grampa, 27) // autogenerated by TidySource.py
TURF_TRACE_DEFINE("[locateTable] flattree lookup redirected")
TURF_TRACE_DEFINE("[createInitialTable] race to create initial table")
Expand Down
143 changes: 82 additions & 61 deletions junction/ConcurrentMap_Grampa.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion junction/ConcurrentMap_LeapFrog.cpp
Expand Up @@ -13,7 +13,7 @@
#include <junction/ConcurrentMap_LeapFrog.h>

namespace junction {

TURF_TRACE_DEFINE_BEGIN(ConcurrentMap_LeapFrog, 17) // autogenerated by TidySource.py
TURF_TRACE_DEFINE("[Mutator] find constructor called")
TURF_TRACE_DEFINE("[Mutator] find was redirected")
Expand Down
89 changes: 48 additions & 41 deletions junction/ConcurrentMap_LeapFrog.h
Expand Up @@ -83,7 +83,7 @@ class ConcurrentMap_LeapFrog {
return;
m_value = m_cell->value.load(turf::Consume);
if (m_value != Value(ValueTraits::Redirect))
return; // Found an existing value
return; // Found an existing value
// We've encountered a Redirect value. Help finish the migration.
TURF_TRACE(ConcurrentMap_LeapFrog, 1, "[Mutator] find was redirected", uptr(m_table), 0);
m_table->jobCoordinator.participate();
Expand All @@ -92,31 +92,32 @@ class ConcurrentMap_LeapFrog {
}

// Constructor: Insert cell
Mutator(ConcurrentMap_LeapFrog& map, Key key) : m_map(map), m_table(map.m_root.load(turf::Consume)), m_value(Value(ValueTraits::NullValue)) {
Mutator(ConcurrentMap_LeapFrog& map, Key key)
: m_map(map), m_table(map.m_root.load(turf::Consume)), m_value(Value(ValueTraits::NullValue)) {
TURF_TRACE(ConcurrentMap_LeapFrog, 2, "[Mutator] insert constructor called", uptr(m_table), uptr(key));
Hash hash = KeyTraits::hash(key);
for (;;) {
m_table = m_map.m_root.load(turf::Consume);
ureg overflowIdx;
switch (Details::insert(hash, m_table, m_cell, overflowIdx)) { // Modifies m_cell
case Details::InsertResult_InsertedNew: {
// We've inserted a new cell. Don't load m_cell->value.
return;
}
case Details::InsertResult_AlreadyFound: {
// The hash was already found in the table.
m_value = m_cell->value.load(turf::Consume);
if (m_value == Value(ValueTraits::Redirect)) {
// We've encountered a Redirect value.
TURF_TRACE(ConcurrentMap_LeapFrog, 3, "[Mutator] insert was redirected", uptr(m_table), uptr(m_value));
break; // Help finish the migration.
}
return; // Found an existing value
}
case Details::InsertResult_Overflow: {
Details::beginTableMigration(m_map, m_table, overflowIdx);
break;
switch (Details::insert(hash, m_table, m_cell, overflowIdx)) { // Modifies m_cell
case Details::InsertResult_InsertedNew: {
// We've inserted a new cell. Don't load m_cell->value.
return;
}
case Details::InsertResult_AlreadyFound: {
// The hash was already found in the table.
m_value = m_cell->value.load(turf::Consume);
if (m_value == Value(ValueTraits::Redirect)) {
// We've encountered a Redirect value.
TURF_TRACE(ConcurrentMap_LeapFrog, 3, "[Mutator] insert was redirected", uptr(m_table), uptr(m_value));
break; // Help finish the migration.
}
return; // Found an existing value
}
case Details::InsertResult_Overflow: {
Details::beginTableMigration(m_map, m_table, overflowIdx);
break;
}
}
// A migration has been started (either by us, or another thread). Participate until it's complete.
m_table->jobCoordinator.participate();
Expand All @@ -132,22 +133,25 @@ class ConcurrentMap_LeapFrog {

Value exchangeValue(Value desired) {
TURF_ASSERT(desired != Value(ValueTraits::NullValue));
TURF_ASSERT(m_cell); // Cell must have been found or inserted
TURF_ASSERT(m_cell); // Cell must have been found or inserted
TURF_TRACE(ConcurrentMap_LeapFrog, 4, "[Mutator::exchangeValue] called", uptr(m_table), uptr(m_value));
for (;;) {
Value oldValue = m_value;
if (m_cell->value.compareExchangeStrong(m_value, desired, turf::ConsumeRelease)) {
// Exchange was successful. Return previous value.
TURF_TRACE(ConcurrentMap_LeapFrog, 5, "[Mutator::exchangeValue] exchanged Value", uptr(m_value), uptr(desired));
TURF_TRACE(ConcurrentMap_LeapFrog, 5, "[Mutator::exchangeValue] exchanged Value", uptr(m_value),
uptr(desired));
Value result = m_value;
m_value = desired; // Leave the mutator in a valid state
m_value = desired; // Leave the mutator in a valid state
return result;
}
// The CAS failed and m_value has been updated with the latest value.
if (m_value != Value(ValueTraits::Redirect)) {
TURF_TRACE(ConcurrentMap_LeapFrog, 6, "[Mutator::exchangeValue] detected race to write value", uptr(m_table), uptr(m_value));
TURF_TRACE(ConcurrentMap_LeapFrog, 6, "[Mutator::exchangeValue] detected race to write value", uptr(m_table),
uptr(m_value));
if (oldValue == Value(ValueTraits::NullValue) && m_value != Value(ValueTraits::NullValue)) {
TURF_TRACE(ConcurrentMap_LeapFrog, 7, "[Mutator::exchangeValue] racing write inserted new value", uptr(m_table), uptr(m_value));
TURF_TRACE(ConcurrentMap_LeapFrog, 7, "[Mutator::exchangeValue] racing write inserted new value",
uptr(m_table), uptr(m_value));
}
// There was a racing write (or erase) to this cell.
// Pretend we exchanged with ourselves, and just let the racing write win.
Expand All @@ -163,25 +167,26 @@ class ConcurrentMap_LeapFrog {
m_table = m_map.m_root.load(turf::Consume);
m_value = Value(ValueTraits::NullValue);
ureg overflowIdx;
switch (Details::insert(hash, m_table, m_cell, overflowIdx)) { // Modifies m_cell
switch (Details::insert(hash, m_table, m_cell, overflowIdx)) { // Modifies m_cell
case Details::InsertResult_AlreadyFound:
m_value = m_cell->value.load(turf::Consume);
if (m_value == Value(ValueTraits::Redirect)) {
TURF_TRACE(ConcurrentMap_LeapFrog, 9, "[Mutator::exchangeValue] was re-redirected", uptr(m_table), uptr(m_value));
TURF_TRACE(ConcurrentMap_LeapFrog, 9, "[Mutator::exchangeValue] was re-redirected", uptr(m_table),
uptr(m_value));
break;
}
goto breakOuter;
case Details::InsertResult_InsertedNew:
goto breakOuter;
case Details::InsertResult_Overflow:
TURF_TRACE(ConcurrentMap_LeapFrog, 10, "[Mutator::exchangeValue] overflow after redirect", uptr(m_table), overflowIdx);
TURF_TRACE(ConcurrentMap_LeapFrog, 10, "[Mutator::exchangeValue] overflow after redirect", uptr(m_table),
overflowIdx);
Details::beginTableMigration(m_map, m_table, overflowIdx);
break;
}
// We were redirected... again
}
breakOuter:
;
breakOuter:;
// Try again in the new table.
}
}
Expand All @@ -191,29 +196,30 @@ class ConcurrentMap_LeapFrog {
}

Value eraseValue() {
TURF_ASSERT(m_cell); // Cell must have been found or inserted
TURF_ASSERT(m_cell); // Cell must have been found or inserted
TURF_TRACE(ConcurrentMap_LeapFrog, 11, "[Mutator::eraseValue] called", uptr(m_table), uptr(m_cell));
for (;;) {
if (m_value == Value(ValueTraits::NullValue))
return Value(m_value);
TURF_ASSERT(m_cell); // m_value is non-NullValue, therefore cell must have been found or inserted.
TURF_ASSERT(m_cell); // m_value is non-NullValue, therefore cell must have been found or inserted.
if (m_cell->value.compareExchangeStrong(m_value, Value(ValueTraits::NullValue), turf::Consume)) {
// Exchange was successful and a non-NULL value was erased and returned by reference in m_value.
TURF_ASSERT(m_value != ValueTraits::NullValue); // Implied by the test at the start of the loop.
TURF_ASSERT(m_value != ValueTraits::NullValue); // Implied by the test at the start of the loop.
Value result = m_value;
m_value = Value(ValueTraits::NullValue); // Leave the mutator in a valid state
m_value = Value(ValueTraits::NullValue); // Leave the mutator in a valid state
return result;
}
// The CAS failed and m_value has been updated with the latest value.
TURF_TRACE(ConcurrentMap_LeapFrog, 12, "[Mutator::eraseValue] detected race to write value", uptr(m_table), uptr(m_cell));
TURF_TRACE(ConcurrentMap_LeapFrog, 12, "[Mutator::eraseValue] detected race to write value", uptr(m_table),
uptr(m_cell));
if (m_value != Value(ValueTraits::Redirect)) {
// There was a racing write (or erase) to this cell.
// Pretend we erased nothing, and just let the racing write win.
return Value(ValueTraits::NullValue);
}
// We've been redirected to a new table.
TURF_TRACE(ConcurrentMap_LeapFrog, 13, "[Mutator::eraseValue] was redirected", uptr(m_table), uptr(m_cell));
Hash hash = m_cell->hash.load(turf::Relaxed); // Re-fetch hash
Hash hash = m_cell->hash.load(turf::Relaxed); // Re-fetch hash
for (;;) {
// Help complete the migration.
m_table->jobCoordinator.participate();
Expand All @@ -227,7 +233,8 @@ class ConcurrentMap_LeapFrog {
m_value = m_cell->value.load(turf::Relaxed);
if (m_value != Value(ValueTraits::Redirect))
break;
TURF_TRACE(ConcurrentMap_LeapFrog, 14, "[Mutator::eraseValue] was re-redirected", uptr(m_table), uptr(m_cell));
TURF_TRACE(ConcurrentMap_LeapFrog, 14, "[Mutator::eraseValue] was re-redirected", uptr(m_table),
uptr(m_cell));
}
}
}
Expand All @@ -252,7 +259,7 @@ class ConcurrentMap_LeapFrog {
return Value(ValueTraits::NullValue);
Value value = cell->value.load(turf::Consume);
if (value != Value(ValueTraits::Redirect))
return value; // Found an existing value
return value; // Found an existing value
// We've been redirected to a new table. Help with the migration.
TURF_TRACE(ConcurrentMap_LeapFrog, 16, "[get] was redirected", uptr(table), uptr(hash));
table->jobCoordinator.participate();
Expand Down Expand Up @@ -295,18 +302,18 @@ class ConcurrentMap_LeapFrog {

void next() {
TURF_ASSERT(m_table);
TURF_ASSERT(isValid() || m_idx == -1); // Either the Iterator is already valid, or we've just started iterating.
TURF_ASSERT(isValid() || m_idx == -1); // Either the Iterator is already valid, or we've just started iterating.
while (++m_idx <= m_table->sizeMask) {
// Index still inside range of table.
typename Details::CellGroup* group = m_table->getCellGroups() + (m_idx >> 2);
typename Details::Cell *cell = group->cells + (m_idx & 3);
typename Details::Cell* cell = group->cells + (m_idx & 3);
m_hash = cell->hash.load(turf::Relaxed);
if (m_hash != KeyTraits::NullHash) {
// Cell has been reserved.
m_value = cell->value.load(turf::Relaxed);
TURF_ASSERT(m_value != Value(ValueTraits::Redirect));
if (m_value != Value(ValueTraits::NullValue))
return; // Yield this cell.
return; // Yield this cell.
}
}
// That's the end of the map.
Expand Down
2 changes: 1 addition & 1 deletion junction/ConcurrentMap_Linear.cpp
Expand Up @@ -13,7 +13,7 @@
#include <junction/ConcurrentMap_Linear.h>

namespace junction {

TURF_TRACE_DEFINE_BEGIN(ConcurrentMap_Linear, 18) // autogenerated by TidySource.py
TURF_TRACE_DEFINE("[Mutator] find constructor called")
TURF_TRACE_DEFINE("[Mutator] find was redirected")
Expand Down

0 comments on commit e8d98a0

Please sign in to comment.