Commit 3bb85dae authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let Futures Barrier::ControlBlock ctor fully construct

Summary:
[Folly] Let Futures `Barrier::ControlBlock` ctor fully construct.

Invoke the constructor when allocating the control block, rather than try to initialize each field afterward.

Differential Revision: D8605292

fbshipit-source-id: d51648a1267ed7e3e13d9a9e8d8e5d1c18e24a98
parent 01336b86
...@@ -39,11 +39,11 @@ Barrier::~Barrier() { ...@@ -39,11 +39,11 @@ Barrier::~Barrier() {
} }
auto Barrier::allocateControlBlock() -> ControlBlock* { auto Barrier::allocateControlBlock() -> ControlBlock* {
auto block = static_cast<ControlBlock*>(malloc(controlBlockSize(size_))); auto storage = malloc(controlBlockSize(size_));
if (!block) { if (!storage) {
throw_exception<std::bad_alloc>(); throw_exception<std::bad_alloc>();
} }
std::atomic_init(&block->valueAndReaderCount, uint64_t(0)); auto block = ::new (storage) ControlBlock();
auto p = promises(block); auto p = promises(block);
uint32_t i = 0; uint32_t i = 0;
......
...@@ -70,7 +70,7 @@ class Barrier { ...@@ -70,7 +70,7 @@ class Barrier {
struct ControlBlock { struct ControlBlock {
// Reader count in most significant 32 bits // Reader count in most significant 32 bits
// Value in least significant 32 bits // Value in least significant 32 bits
std::atomic<uint64_t> valueAndReaderCount; std::atomic<uint64_t> valueAndReaderCount{0};
}; };
struct ControlBlockAndPromise { struct ControlBlockAndPromise {
......
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 to comment