From: Jeff Preshing Date: Mon, 14 Mar 2016 15:53:08 +0000 (-0400) Subject: Rename set() to assign() X-Git-Url: http://plrg.eecs.uci.edu/git/?p=junction.git;a=commitdiff_plain;h=ce08f11c83396f629f998fe9e05ff1628f1e2677 Rename set() to assign() Will avoid ambiguity when ConcurrentSets are added to Junction, and more consistent with C++17's insert_or_assign. --- diff --git a/README.md b/README.md index b4361a0..d603544 100644 --- a/README.md +++ b/README.md @@ -102,9 +102,9 @@ The `JUNCTION_USERCONFIG` variable works in a similar way. As an example, take a A Junction map is a lot like a big array of `std::atomic<>` variables, where the key is an index into the array. More precisely: * All of a Junction map's member functions, together with its `Mutator` member functions, are atomic with respect to each other, so you can safely call them from any thread without mutual exclusion. -* If an `set` [happens before](http://preshing.com/20130702/the-happens-before-relation/) a `get` with the same key, the `get` will return the value set, except if another operation changes the value in between. Any [synchronizing operation](http://preshing.com/20130823/the-synchronizes-with-relation/) will establish this relationship. -* For Linear, Leapfrog and Grampa maps, `set` is a [release](http://preshing.com/20120913/acquire-and-release-semantics/) operation and `get` is a [consume](http://preshing.com/20140709/the-purpose-of-memory_order_consume-in-cpp11/) operation, so you can safely pass non-atomic information between threads using a pointer. For Crude maps, all operations are relaxed. -* In the current version, you must not set while concurrently using an `Iterator`. +* If an `assign` [happens before](http://preshing.com/20130702/the-happens-before-relation/) a `get` with the same key, the `get` will return the value it inserted, except if another operation changes the value in between. Any [synchronizing operation](http://preshing.com/20130823/the-synchronizes-with-relation/) will establish this relationship. +* For Linear, Leapfrog and Grampa maps, `assign` is a [release](http://preshing.com/20120913/acquire-and-release-semantics/) operation and `get` is a [consume](http://preshing.com/20140709/the-purpose-of-memory_order_consume-in-cpp11/) operation, so you can safely pass non-atomic information between threads using a pointer. For Crude maps, all operations are relaxed. +* In the current version, you must not `assign` while concurrently using an `Iterator`. ## Feedback diff --git a/junction/ConcurrentMap_Crude.h b/junction/ConcurrentMap_Crude.h index d064a48..0d8fd16 100644 --- a/junction/ConcurrentMap_Crude.h +++ b/junction/ConcurrentMap_Crude.h @@ -49,7 +49,7 @@ public: delete[] m_cells; } - void set(Key key, Value value) { + void assign(Key key, Value value) { TURF_ASSERT(key != KeyTraits::NullKey); TURF_ASSERT(value != Value(ValueTraits::NullValue)); diff --git a/junction/ConcurrentMap_Grampa.h b/junction/ConcurrentMap_Grampa.h index c8fdc8d..8422b22 100644 --- a/junction/ConcurrentMap_Grampa.h +++ b/junction/ConcurrentMap_Grampa.h @@ -398,7 +398,7 @@ public: } } - void setValue(Value desired) { + void assignValue(Value desired) { exchangeValue(desired); } @@ -478,7 +478,7 @@ public: } } - Value set(Key key, Value desired) { + Value assign(Key key, Value desired) { Mutator iter(*this, key); return iter.exchangeValue(desired); } diff --git a/junction/ConcurrentMap_Leapfrog.h b/junction/ConcurrentMap_Leapfrog.h index 3a8493e..4850f0d 100644 --- a/junction/ConcurrentMap_Leapfrog.h +++ b/junction/ConcurrentMap_Leapfrog.h @@ -197,7 +197,7 @@ public: } } - void setValue(Value desired) { + void assignValue(Value desired) { exchangeValue(desired); } @@ -273,7 +273,7 @@ public: } } - Value set(Key key, Value desired) { + Value assign(Key key, Value desired) { Mutator iter(*this, key); return iter.exchangeValue(desired); } diff --git a/junction/ConcurrentMap_Linear.h b/junction/ConcurrentMap_Linear.h index 7e268e5..6e74efa 100644 --- a/junction/ConcurrentMap_Linear.h +++ b/junction/ConcurrentMap_Linear.h @@ -193,7 +193,7 @@ public: } } - void setValue(Value desired) { + void assignValue(Value desired) { exchangeValue(desired); } @@ -270,7 +270,7 @@ public: } } - Value set(Key key, Value desired) { + Value assign(Key key, Value desired) { Mutator iter(*this, key); return iter.exchangeValue(desired); } diff --git a/junction/SingleMap_Linear.h b/junction/SingleMap_Linear.h index ff1fd52..5716b4c 100644 --- a/junction/SingleMap_Linear.h +++ b/junction/SingleMap_Linear.h @@ -189,7 +189,7 @@ public: return iter.isValid() ? iter.getValue() : NULL; } - Value set(const Key& key, Value desired) { + Value assign(const Key& key, Value desired) { Mutator iter(*this, key); return iter.exchangeValue(desired); } diff --git a/junction/extra/impl/MapAdapter_CDS_Cuckoo.h b/junction/extra/impl/MapAdapter_CDS_Cuckoo.h index 71fef30..56ea0df 100644 --- a/junction/extra/impl/MapAdapter_CDS_Cuckoo.h +++ b/junction/extra/impl/MapAdapter_CDS_Cuckoo.h @@ -86,7 +86,7 @@ public: Map(ureg capacity) : m_map() { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { m_map.insert(key, value); } diff --git a/junction/extra/impl/MapAdapter_CDS_Michael.h b/junction/extra/impl/MapAdapter_CDS_Michael.h index bd6f1cd..8820b79 100644 --- a/junction/extra/impl/MapAdapter_CDS_Michael.h +++ b/junction/extra/impl/MapAdapter_CDS_Michael.h @@ -86,7 +86,7 @@ public: Map(ureg capacity) : m_map(capacity, 1) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { m_map.insert(key, value); } diff --git a/junction/extra/impl/MapAdapter_Folly.h b/junction/extra/impl/MapAdapter_Folly.h index 2cc8376..2054483 100644 --- a/junction/extra/impl/MapAdapter_Folly.h +++ b/junction/extra/impl/MapAdapter_Folly.h @@ -54,7 +54,7 @@ public: Map(ureg capacity) : m_map(capacity) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { m_map.insert(std::make_pair(key, value)); } diff --git a/junction/extra/impl/MapAdapter_LibCuckoo.h b/junction/extra/impl/MapAdapter_LibCuckoo.h index 9e83817..784f9b0 100644 --- a/junction/extra/impl/MapAdapter_LibCuckoo.h +++ b/junction/extra/impl/MapAdapter_LibCuckoo.h @@ -54,7 +54,7 @@ public: Map(ureg capacity) : m_map(capacity) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { m_map.insert(key, value); } diff --git a/junction/extra/impl/MapAdapter_Linear_Mutex.h b/junction/extra/impl/MapAdapter_Linear_Mutex.h index d383663..3592a1f 100644 --- a/junction/extra/impl/MapAdapter_Linear_Mutex.h +++ b/junction/extra/impl/MapAdapter_Linear_Mutex.h @@ -52,9 +52,9 @@ public: Map(ureg capacity) : m_map(capacity) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { turf::LockGuard guard(m_mutex); - m_map.set(key, value); + m_map.assign(key, value); } void* get(u32 key) { diff --git a/junction/extra/impl/MapAdapter_Linear_RWLock.h b/junction/extra/impl/MapAdapter_Linear_RWLock.h index 8c08559..24bb227 100644 --- a/junction/extra/impl/MapAdapter_Linear_RWLock.h +++ b/junction/extra/impl/MapAdapter_Linear_RWLock.h @@ -52,9 +52,9 @@ public: Map(ureg capacity) : m_map(capacity) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { turf::ExclusiveLockGuard guard(m_rwLock); - m_map.set(key, value); + m_map.assign(key, value); } void* get(u32 key) { diff --git a/junction/extra/impl/MapAdapter_NBDS.h b/junction/extra/impl/MapAdapter_NBDS.h index bd2bc86..13e9334 100644 --- a/junction/extra/impl/MapAdapter_NBDS.h +++ b/junction/extra/impl/MapAdapter_NBDS.h @@ -69,7 +69,7 @@ public: ht_free(m_map); } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { ht_cas(m_map, key, CAS_EXPECT_WHATEVER, (map_val_t) value); } diff --git a/junction/extra/impl/MapAdapter_Null.h b/junction/extra/impl/MapAdapter_Null.h index af17120..f25dd9d 100644 --- a/junction/extra/impl/MapAdapter_Null.h +++ b/junction/extra/impl/MapAdapter_Null.h @@ -45,7 +45,7 @@ public: Map(ureg) { } - void set(u32, void*) { + void assign(u32, void*) { } void* get(u32) { diff --git a/junction/extra/impl/MapAdapter_StdMap.h b/junction/extra/impl/MapAdapter_StdMap.h index 8425936..9fde8f4 100644 --- a/junction/extra/impl/MapAdapter_StdMap.h +++ b/junction/extra/impl/MapAdapter_StdMap.h @@ -52,7 +52,7 @@ public: Map(ureg) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { std::lock_guard guard(m_mutex); m_map[key] = value; } diff --git a/junction/extra/impl/MapAdapter_TBB.h b/junction/extra/impl/MapAdapter_TBB.h index aa442ae..3e9bc01 100644 --- a/junction/extra/impl/MapAdapter_TBB.h +++ b/junction/extra/impl/MapAdapter_TBB.h @@ -54,7 +54,7 @@ public: Map(ureg capacity) : m_map(capacity) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { m_map.insert(std::make_pair(key, value)); } diff --git a/junction/extra/impl/MapAdapter_Tervel.h b/junction/extra/impl/MapAdapter_Tervel.h index d294278..440dff0 100644 --- a/junction/extra/impl/MapAdapter_Tervel.h +++ b/junction/extra/impl/MapAdapter_Tervel.h @@ -62,7 +62,7 @@ public: Map(ureg capacity) : m_map(capacity, 3) { } - void set(u32 key, void* value) { + void assign(u32 key, void* value) { m_map.insert(key, (u64) value); } diff --git a/samples/MallocTest/MallocTest.cpp b/samples/MallocTest/MallocTest.cpp index a6695d2..c0e18cf 100644 --- a/samples/MallocTest/MallocTest.cpp +++ b/samples/MallocTest/MallocTest.cpp @@ -28,7 +28,7 @@ int main() { std::cout << "Population=" << population << ", inUse=" << TURF_HEAP.getInUseBytes() << std::endl; #endif for (; population < i * 5000; population++) - map.set(population + 1, (void*) ((population << 2) | 3)); + map.assign(population + 1, (void*) ((population << 2) | 3)); } return 0; diff --git a/samples/MapCorrectnessTests/TestChurn.h b/samples/MapCorrectnessTests/TestChurn.h index ca2b321..ac3800e 100644 --- a/samples/MapCorrectnessTests/TestChurn.h +++ b/samples/MapCorrectnessTests/TestChurn.h @@ -79,7 +79,7 @@ public: u32 key = thread.insertIndex * m_relativePrime; key = key ^ (key >> 16); if (key >= 2) { - m_map.set(key, (void*) uptr(key)); + m_map.assign(key, (void*) uptr(key)); } if (++thread.insertIndex >= thread.rangeHi) thread.insertIndex = thread.rangeLo; @@ -96,7 +96,7 @@ public: u32 key = thread.insertIndex * m_relativePrime; key = key ^ (key >> 16); if (key >= 2) { - m_map.set(key, (void*) uptr(key)); + m_map.assign(key, (void*) uptr(key)); } if (++thread.insertIndex >= thread.rangeHi) thread.insertIndex = thread.rangeLo; diff --git a/samples/MapCorrectnessTests/TestInsertDifferentKeys.h b/samples/MapCorrectnessTests/TestInsertDifferentKeys.h index 7e7bdaa..c0e2211 100644 --- a/samples/MapCorrectnessTests/TestInsertDifferentKeys.h +++ b/samples/MapCorrectnessTests/TestInsertDifferentKeys.h @@ -36,7 +36,7 @@ public: u32 key = index * m_relativePrime; key = key ^ (key >> 16); if (key >= 2) { // Don't insert 0 or 1 - m_map->set(key, (void*) uptr(key)); + m_map->assign(key, (void*) uptr(key)); keysRemaining--; } index++; diff --git a/samples/MapCorrectnessTests/TestInsertSameKeys.h b/samples/MapCorrectnessTests/TestInsertSameKeys.h index 8510d8c..63e9172 100644 --- a/samples/MapCorrectnessTests/TestInsertSameKeys.h +++ b/samples/MapCorrectnessTests/TestInsertSameKeys.h @@ -36,7 +36,7 @@ public: u32 key = index * m_relativePrime; key = key ^ (key >> 16); if (key >= 2) { // Don't insert 0 or 1 - m_map->set(key, (void*) uptr(key)); + m_map->assign(key, (void*) uptr(key)); keysRemaining--; } index++; diff --git a/samples/MapLinearizabilityTest/MapLinearizabilityTest.cpp b/samples/MapLinearizabilityTest/MapLinearizabilityTest.cpp index 1532de5..243d32a 100644 --- a/samples/MapLinearizabilityTest/MapLinearizabilityTest.cpp +++ b/samples/MapLinearizabilityTest/MapLinearizabilityTest.cpp @@ -49,10 +49,10 @@ public: if (threadIndex == 0) { // We store 2 because Junction maps reserve 1 for the default Redirect value. // The default can be overridden, but this is easier. - m_map.set(x, (void*) 2); + m_map.assign(x, (void*) 2); m_r1 = (uptr) m_map.get(y); } else { - m_map.set(y, (void*) 2); + m_map.assign(y, (void*) 2); m_r2 = (uptr) m_map.get(x); } } @@ -89,11 +89,11 @@ public: case 0: // We store 2 because Junction maps reserve 1 for the default Redirect value. // The default can be overridden, but this is easier. - m_map.set(x, (void*) 2); + m_map.assign(x, (void*) 2); break; case 1: - m_map.set(y, (void*) 2); + m_map.assign(y, (void*) 2); break; case 2: diff --git a/samples/MapPerformanceTests/MapPerformanceTests.cpp b/samples/MapPerformanceTests/MapPerformanceTests.cpp index d0a5e3d..ceead97 100644 --- a/samples/MapPerformanceTests/MapPerformanceTests.cpp +++ b/samples/MapPerformanceTests/MapPerformanceTests.cpp @@ -126,7 +126,7 @@ public: MapAdapter::Map* map = m_shared.map; for (ureg i = 0; i < m_shared.numKeysPerThread; i++) { u32 key = m_addIndex * Prime; - map->set(key, (void*) (key & ~uptr(3))); + map->assign(key, (void*) (key & ~uptr(3))); if (++m_addIndex == m_rangeHi) m_addIndex = m_rangeLo; } @@ -155,7 +155,7 @@ public: break; u32 key = m_addIndex * Prime; if (key >= 2) { - map->set(key, (void*) uptr(key)); + map->assign(key, (void*) uptr(key)); stats.mapOpsDone++; } if (++m_addIndex == m_rangeHi) diff --git a/samples/MapScalabilityTests/MapScalabilityTests.cpp b/samples/MapScalabilityTests/MapScalabilityTests.cpp index 0841bdd..a9fa58b 100644 --- a/samples/MapScalabilityTests/MapScalabilityTests.cpp +++ b/samples/MapScalabilityTests/MapScalabilityTests.cpp @@ -103,7 +103,7 @@ public: for (ureg i = 0; i < m_shared.numKeysPerThread; i++) { u32 key = m_addIndex * Prime; if (key >= 2) - map->set(key, (void*) uptr(key)); + map->assign(key, (void*) uptr(key)); if (++m_addIndex == m_rangeHi) m_addIndex = m_rangeLo; } @@ -130,7 +130,7 @@ public: break; u32 key = m_addIndex * Prime; if (key >= 2) { - map->set(key, (void*) uptr(key)); + map->assign(key, (void*) uptr(key)); stats.mapOpsDone++; } if (++m_addIndex == m_rangeHi)