Skip to content

Commit 4b5fb50

Browse files
Copilotanasdorbani
andcommitted
Replace busy-wait with std::this_thread::sleep_for in StorageAttachmentGuard::Wait
Co-authored-by: anasdorbani <95044293+anasdorbani@users.noreply.github.com>
1 parent 28d165e commit 4b5fb50

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

_codeql_detected_source_root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

src/core/config/config.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "duckdb/common/file_system.hpp"
33
#include "flock/secret_manager/secret_manager.hpp"
44
#include <chrono>
5+
#include <thread>
56
#include <fmt/format.h>
67

78
namespace flock {
@@ -144,11 +145,7 @@ bool Config::StorageAttachmentGuard::TryDetach() {
144145
}
145146

146147
void Config::StorageAttachmentGuard::Wait(int milliseconds) {
147-
auto start = std::chrono::steady_clock::now();
148-
auto duration = std::chrono::milliseconds(milliseconds);
149-
while (std::chrono::steady_clock::now() - start < duration) {
150-
// Busy-wait until the specified duration has elapsed
151-
}
148+
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
152149
}
153150

154151
Config::StorageAttachmentGuard::StorageAttachmentGuard(duckdb::Connection& con, bool read_only)
@@ -201,11 +198,7 @@ bool Config::StorageAttachmentGuard::TryDetach() {
201198
}
202199

203200
void Config::StorageAttachmentGuard::Wait(int milliseconds) {
204-
auto start = std::chrono::steady_clock::now();
205-
auto duration = std::chrono::milliseconds(milliseconds);
206-
while (std::chrono::steady_clock::now() - start < duration) {
207-
// Busy-wait until the specified duration has elapsed
208-
}
201+
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
209202
}
210203

211204
Config::StorageAttachmentGuard::StorageAttachmentGuard(duckdb::Connection& con, bool read_only)

0 commit comments

Comments
 (0)