Skip to content

Commit

Permalink
Respond to PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
aliddell committed Jul 9, 2024
1 parent eef0db7 commit 1377ed4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/common/thread.pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
namespace zarr = acquire::sink::zarr;
namespace common = zarr::common;

common::ThreadPool::ThreadPool(size_t n_threads,
common::ThreadPool::ThreadPool(unsigned int n_threads,
std::function<void(const std::string&)> err)
: error_handler_{ err }
, is_accepting_jobs_{ true }
{
const unsigned int one = 1;
n_threads = std::clamp(
n_threads,
(size_t)1,
(size_t)std::max(std::thread::hardware_concurrency(), (unsigned)1));
n_threads, one, std::max(std::thread::hardware_concurrency(), one));

for (auto i = 0; i < n_threads; ++i) {
threads_.emplace_back([this] { thread_worker_(); });
Expand All @@ -32,11 +31,12 @@ common::ThreadPool::~ThreadPool() noexcept
void
common::ThreadPool::push_to_job_queue(JobT&& job)
{
std::unique_lock lock(jobs_mutex_);
CHECK(is_accepting_jobs_);
{
std::unique_lock lock(jobs_mutex_);
CHECK(is_accepting_jobs_);

jobs_.push(std::move(job));
lock.unlock();
jobs_.push(std::move(job));
}

cv_.notify_one();
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/thread.pool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ThreadPool final
// std::string& argument to the error handler is a diagnostic message from
// the failing job and is logged to the error stream by the Zarr driver when
// the next call to `append()` is made.
ThreadPool(size_t n_threads, std::function<void(const std::string&)> err);
ThreadPool(unsigned int n_threads, std::function<void(const std::string&)> err);
~ThreadPool() noexcept;

void push_to_job_queue(JobT&& job);
Expand Down
6 changes: 1 addition & 5 deletions src/common/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,11 @@ common::split_uri(const std::string& uri)
auto end = uri.find_first_of(delim);

std::vector<std::string> out;
while (end <= std::string::npos) {
while (end != std::string::npos) {
if (end > begin) {
out.emplace_back(uri.substr(begin, end - begin));
}

if (end == std::string::npos) {
break;
}

begin = end + 1;
end = uri.find_first_of(delim, begin);
}
Expand Down

0 comments on commit 1377ed4

Please sign in to comment.