From c17b8f800c9270eff3f1d3114a8ee1efea71f210 Mon Sep 17 00:00:00 2001 From: longqm Date: Fri, 10 Jan 2025 02:28:02 +0000 Subject: [PATCH] remove std::thread read_csv_worker, useless and buggy in seastar --- include/internal/csv_reader.cpp | 8 +++++--- include/internal/csv_reader.hpp | 13 ++++++------ include/internal/csv_reader_iterator.cpp | 5 +++-- single_include/csv.hpp | 26 ++++++++++++++---------- single_include_test/csv.hpp | 26 ++++++++++++++---------- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/include/internal/csv_reader.cpp b/include/internal/csv_reader.cpp index 008a487..81e4348 100644 --- a/include/internal/csv_reader.cpp +++ b/include/internal/csv_reader.cpp @@ -280,10 +280,12 @@ namespace csv { return false; else { // Reading thread is not active => start another one - if (this->read_csv_worker.joinable()) - this->read_csv_worker.join(); + // if (this->read_csv_worker.joinable()) + // this->read_csv_worker.join(); + + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + this->read_csv(internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); } } else if (this->records->front().size() != this->n_cols && diff --git a/include/internal/csv_reader.hpp b/include/internal/csv_reader.hpp index 300e7da..cf75ed2 100644 --- a/include/internal/csv_reader.hpp +++ b/include/internal/csv_reader.hpp @@ -134,9 +134,9 @@ namespace csv { CSVReader& operator=(const CSVReader&) = delete; // No copy assignment CSVReader& operator=(CSVReader&& other) = default; ~CSVReader() { - if (this->read_csv_worker.joinable()) { - this->read_csv_worker.join(); - } + // if (this->read_csv_worker.joinable()) { + // this->read_csv_worker.join(); + // } } /** @name Retrieving CSV Rows */ @@ -216,13 +216,14 @@ namespace csv { /** @name Multi-Threaded File Reading: Flags and State */ ///@{ - std::thread read_csv_worker; /**< Worker thread for read_csv() */ + // std::thread read_csv_worker; /**< Worker thread for read_csv() */ ///@} /** Read initial chunk to get metadata */ void initial_read() { - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker.join(); + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + // this->read_csv_worker.join(); + this->read_csv(internals::ITERATION_CHUNK_SIZE); } void trim_header(); diff --git a/include/internal/csv_reader_iterator.cpp b/include/internal/csv_reader_iterator.cpp index 4ac0e6f..58d901d 100644 --- a/include/internal/csv_reader_iterator.cpp +++ b/include/internal/csv_reader_iterator.cpp @@ -8,8 +8,9 @@ namespace csv { /** Return an iterator to the first row in the reader */ CSV_INLINE CSVReader::iterator CSVReader::begin() { if (this->records->empty()) { - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker.join(); + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + // this->read_csv_worker.join(); + this->read_csv(internals::ITERATION_CHUNK_SIZE); // Still empty => return end iterator if (this->records->empty()) return this->end(); diff --git a/single_include/csv.hpp b/single_include/csv.hpp index d68ff65..a50fde7 100644 --- a/single_include/csv.hpp +++ b/single_include/csv.hpp @@ -6354,9 +6354,9 @@ namespace csv { CSVReader& operator=(const CSVReader&) = delete; // No copy assignment CSVReader& operator=(CSVReader&& other) = default; ~CSVReader() { - if (this->read_csv_worker.joinable()) { - this->read_csv_worker.join(); - } + // if (this->read_csv_worker.joinable()) { + // this->read_csv_worker.join(); + // } } /** @name Retrieving CSV Rows */ @@ -6436,13 +6436,14 @@ namespace csv { /** @name Multi-Threaded File Reading: Flags and State */ ///@{ - std::thread read_csv_worker; /**< Worker thread for read_csv() */ + // std::thread read_csv_worker; /**< Worker thread for read_csv() */ ///@} /** Read initial chunk to get metadata */ void initial_read() { - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker.join(); + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + // this->read_csv_worker.join(); + this->read_csv(internals::ITERATION_CHUNK_SIZE); } void trim_header(); @@ -7576,10 +7577,12 @@ namespace csv { return false; else { // Reading thread is not active => start another one - if (this->read_csv_worker.joinable()) - this->read_csv_worker.join(); + // if (this->read_csv_worker.joinable()) + // this->read_csv_worker.join(); + + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + this->read_csv(internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); } } else if (this->records->front().size() != this->n_cols && @@ -7733,8 +7736,9 @@ namespace csv { /** Return an iterator to the first row in the reader */ CSV_INLINE CSVReader::iterator CSVReader::begin() { if (this->records->empty()) { - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker.join(); + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + // this->read_csv_worker.join(); + this->read_csv(internals::ITERATION_CHUNK_SIZE); // Still empty => return end iterator if (this->records->empty()) return this->end(); diff --git a/single_include_test/csv.hpp b/single_include_test/csv.hpp index d68ff65..a50fde7 100644 --- a/single_include_test/csv.hpp +++ b/single_include_test/csv.hpp @@ -6354,9 +6354,9 @@ namespace csv { CSVReader& operator=(const CSVReader&) = delete; // No copy assignment CSVReader& operator=(CSVReader&& other) = default; ~CSVReader() { - if (this->read_csv_worker.joinable()) { - this->read_csv_worker.join(); - } + // if (this->read_csv_worker.joinable()) { + // this->read_csv_worker.join(); + // } } /** @name Retrieving CSV Rows */ @@ -6436,13 +6436,14 @@ namespace csv { /** @name Multi-Threaded File Reading: Flags and State */ ///@{ - std::thread read_csv_worker; /**< Worker thread for read_csv() */ + // std::thread read_csv_worker; /**< Worker thread for read_csv() */ ///@} /** Read initial chunk to get metadata */ void initial_read() { - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker.join(); + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + // this->read_csv_worker.join(); + this->read_csv(internals::ITERATION_CHUNK_SIZE); } void trim_header(); @@ -7576,10 +7577,12 @@ namespace csv { return false; else { // Reading thread is not active => start another one - if (this->read_csv_worker.joinable()) - this->read_csv_worker.join(); + // if (this->read_csv_worker.joinable()) + // this->read_csv_worker.join(); + + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + this->read_csv(internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); } } else if (this->records->front().size() != this->n_cols && @@ -7733,8 +7736,9 @@ namespace csv { /** Return an iterator to the first row in the reader */ CSV_INLINE CSVReader::iterator CSVReader::begin() { if (this->records->empty()) { - this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); - this->read_csv_worker.join(); + // this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); + // this->read_csv_worker.join(); + this->read_csv(internals::ITERATION_CHUNK_SIZE); // Still empty => return end iterator if (this->records->empty()) return this->end();