@@ -38,13 +38,10 @@ namespace openPMD::internal
3838{
3939void AwsAsyncCounter::wait ()
4040{
41- // std::cerr << "Waiting for remaining tasks. Have " << completion_counter
42- // << " of " << request_counter << std::endl;
4341 size_t target = this ->request_counter ;
4442 std::unique_lock lk (this ->mutex );
4543 this ->event .wait (
4644 lk, [this , target]() { return this ->completion_counter >= target; });
47- // std::cerr << "Finished waiting for remaining tasks" << std::endl;
4845}
4946
5047void AwsAsyncCounter::add_task ()
@@ -62,7 +59,10 @@ void AwsAsyncCounter::add_and_notify_result()
6259
6360AwsAsyncCounter::~AwsAsyncCounter ()
6461{
62+ std::cerr << " Waiting for remaining tasks. Have " << completion_counter
63+ << " of " << request_counter << std::endl;
6564 this ->wait ();
65+ std::cerr << " Finished waiting for remaining tasks" << std::endl;
6666}
6767
6868ExternalBlockStorageAws::ExternalBlockStorageAws (
@@ -89,7 +89,11 @@ ExternalBlockStorageAws::ExternalBlockStorageAws(
8989 std::cout << " Bucket created: " << m_bucketName << std::endl;
9090 }
9191}
92- ExternalBlockStorageAws::~ExternalBlockStorageAws () = default ;
92+ ExternalBlockStorageAws::~ExternalBlockStorageAws ()
93+ {
94+ // We need to wait for late operations before doing anything else.
95+ m_async.reset ();
96+ }
9397
9498auto ExternalBlockStorageAws::put (
9599 std::string const &identifier, auxiliary::WriteBuffer data, size_t len)
@@ -130,14 +134,17 @@ auto ExternalBlockStorageAws::put(
130134 auto &async_counter = *std::visit (
131135 auxiliary::overloaded{
132136 [this ](auxiliary::WriteBuffer::CopyableUniquePtr const &) {
137+ std::cout << " Using unique pointer" << std::endl;
133138 return &this ->m_async ->unique_ptr_operations ;
134139 },
135140 [this ](auxiliary::WriteBuffer::SharedPtr const &) {
141+ std::cout << " Using shared pointer" << std::endl;
136142 return &this ->m_async ->shared_ptr_operations ;
137143 }},
138144 data.as_variant <auxiliary::WriteBufferTypes>());
139145 auto responseReceivedHandler =
140146 [&async_counter,
147+ sanitized,
141148 /*
142149 * Need to keep buffers alive until they have been asynchronously
143150 * read. Use the closure captures for this. Wrap the WriteBuffer
@@ -159,8 +166,8 @@ auto ExternalBlockStorageAws::put(
159166 }
160167 else
161168 {
162- std::cerr << " Asynchronous upload failed: "
163- << put_outcome.GetError ().GetMessage ()
169+ std::cerr << " Asynchronous upload failed for ' " << sanitized
170+ << " ': " << put_outcome.GetError ().GetMessage ()
164171 << std::endl;
165172 }
166173 async_counter.add_and_notify_result ();
0 commit comments