diff --git a/folly/futures/Barrier.cpp b/folly/futures/Barrier.cpp index 1ed458b2ac2a5e7aba66bb202c55f8ad96d6c52e..cb31012ac2fe8d0796f522ac41df7a6dd5d6a6ef 100644 --- a/folly/futures/Barrier.cpp +++ b/folly/futures/Barrier.cpp @@ -39,11 +39,11 @@ Barrier::~Barrier() { } auto Barrier::allocateControlBlock() -> ControlBlock* { - auto block = static_cast<ControlBlock*>(malloc(controlBlockSize(size_))); - if (!block) { + auto storage = malloc(controlBlockSize(size_)); + if (!storage) { throw_exception<std::bad_alloc>(); } - std::atomic_init(&block->valueAndReaderCount, uint64_t(0)); + auto block = ::new (storage) ControlBlock(); auto p = promises(block); uint32_t i = 0; diff --git a/folly/futures/Barrier.h b/folly/futures/Barrier.h index 012d15d78e4f6d3ed987522331e9ffcdeaffdf3c..4c6d9cdb0127eb0389dbaa7f1f4ebd34c8866bc1 100644 --- a/folly/futures/Barrier.h +++ b/folly/futures/Barrier.h @@ -70,7 +70,7 @@ class Barrier { struct ControlBlock { // Reader count in most significant 32 bits // Value in least significant 32 bits - std::atomic<uint64_t> valueAndReaderCount; + std::atomic<uint64_t> valueAndReaderCount{0}; }; struct ControlBlockAndPromise {