Skip to content

Commit 0a40449

Browse files
committed
Attempt to resolve -Wsign-conversion warnings in concurrentqueue.h (see #294)
1 parent 22c78da commit 0a40449

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

concurrentqueue.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ class ConcurrentQueue
20182018
// block size (in order to get a correct signed block count offset in all cases):
20192019
auto headBase = localBlockIndex->entries[localBlockIndexHead].base;
20202020
auto blockBaseIndex = index & ~static_cast<index_t>(BLOCK_SIZE - 1);
2021-
auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(blockBaseIndex - headBase) / BLOCK_SIZE);
2021+
auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(blockBaseIndex - headBase) / static_cast<typename std::make_signed<index_t>::type>(BLOCK_SIZE));
20222022
auto block = localBlockIndex->entries[(localBlockIndexHead + offset) & (localBlockIndex->size - 1)].block;
20232023

20242024
// Dequeue
@@ -2279,7 +2279,7 @@ class ConcurrentQueue
22792279

22802280
auto headBase = localBlockIndex->entries[localBlockIndexHead].base;
22812281
auto firstBlockBaseIndex = firstIndex & ~static_cast<index_t>(BLOCK_SIZE - 1);
2282-
auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(firstBlockBaseIndex - headBase) / BLOCK_SIZE);
2282+
auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(firstBlockBaseIndex - headBase) / static_cast<typename std::make_signed<index_t>::type>(BLOCK_SIZE));
22832283
auto indexIndex = (localBlockIndexHead + offset) & (localBlockIndex->size - 1);
22842284

22852285
// Iterate the blocks and dequeue
@@ -2962,7 +2962,7 @@ class ConcurrentQueue
29622962
assert(tailBase != INVALID_BLOCK_BASE);
29632963
// Note: Must use division instead of shift because the index may wrap around, causing a negative
29642964
// offset, whose negativity we want to preserve
2965-
auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(index - tailBase) / BLOCK_SIZE);
2965+
auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(index - tailBase) / static_cast<typename std::make_signed<index_t>::type>(BLOCK_SIZE));
29662966
size_t idx = (tail + offset) & (localBlockIndex->capacity - 1);
29672967
assert(localBlockIndex->index[idx]->key.load(std::memory_order_relaxed) == index && localBlockIndex->index[idx]->value.load(std::memory_order_relaxed) != nullptr);
29682968
return idx;
@@ -3415,7 +3415,7 @@ class ConcurrentQueue
34153415
// Look for the id in this hash
34163416
auto index = hashedId;
34173417
while (true) { // Not an infinite loop because at least one slot is free in the hash table
3418-
index &= hash->capacity - 1;
3418+
index &= hash->capacity - 1u;
34193419

34203420
auto probedKey = hash->entries[index].key.load(std::memory_order_relaxed);
34213421
if (probedKey == id) {
@@ -3428,7 +3428,7 @@ class ConcurrentQueue
34283428
if (hash != mainHash) {
34293429
index = hashedId;
34303430
while (true) {
3431-
index &= mainHash->capacity - 1;
3431+
index &= mainHash->capacity - 1u;
34323432
auto empty = details::invalid_thread_id;
34333433
#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED
34343434
auto reusable = details::invalid_thread_id2;
@@ -3464,7 +3464,7 @@ class ConcurrentQueue
34643464
// locked block).
34653465
mainHash = implicitProducerHash.load(std::memory_order_acquire);
34663466
if (newCount >= (mainHash->capacity >> 1)) {
3467-
auto newCapacity = mainHash->capacity << 1;
3467+
size_t newCapacity = mainHash->capacity << 1;
34683468
while (newCount >= (newCapacity >> 1)) {
34693469
newCapacity <<= 1;
34703470
}
@@ -3511,7 +3511,7 @@ class ConcurrentQueue
35113511

35123512
auto index = hashedId;
35133513
while (true) {
3514-
index &= mainHash->capacity - 1;
3514+
index &= mainHash->capacity - 1u;
35153515
auto empty = details::invalid_thread_id;
35163516
#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED
35173517
auto reusable = details::invalid_thread_id2;
@@ -3555,7 +3555,7 @@ class ConcurrentQueue
35553555
for (; hash != nullptr; hash = hash->prev) {
35563556
auto index = hashedId;
35573557
do {
3558-
index &= hash->capacity - 1;
3558+
index &= hash->capacity - 1u;
35593559
probedKey = id;
35603560
if (hash->entries[index].key.compare_exchange_strong(probedKey, details::invalid_thread_id2, std::memory_order_seq_cst, std::memory_order_relaxed)) {
35613561
break;

0 commit comments

Comments
 (0)