Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement move semantics and disable copy semantics for the new PipeReader #342

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gpu-simulator/trace-parser/trace_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,21 @@ bool PipeReader::hasEnding(const std::string &fullString,
ending.length(), ending));
}
return false;
}

PipeReader::PipeReader(PipeReader &&other) noexcept
: pipe(other.pipe), command(other.command) {
other.pipe = NULL;
other.command = {};
}

PipeReader &PipeReader::operator=(PipeReader &&other) noexcept {
if (this != &other) {
pipe = other.pipe;
command = other.command;

other.pipe = NULL;
other.command = {};
}
return *this;
}
12 changes: 11 additions & 1 deletion gpu-simulator/trace-parser/trace_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ struct inst_trace_t {
class PipeReader {
public:
PipeReader(const std::string &filePath);
void OpenFile(const std::string &filePath);

// Destructor to close the pipe
~PipeReader() {
Expand All @@ -87,6 +86,15 @@ class PipeReader {
}
}

// It does not make sense to implement copy semantics for PipeReader,
// because each instance should hold a unique Linux pipe handle
PipeReader(const PipeReader &) = delete;
PipeReader &operator=(const PipeReader &) = delete;

// Move semantics can be supported
PipeReader(PipeReader &&) noexcept;
PipeReader &operator=(PipeReader &&) noexcept;

// Read one line
bool readLine(std::string &line);

Expand All @@ -97,6 +105,8 @@ class PipeReader {
// Helper function to check if a string ends with a specific suffix (file
// extension)
bool hasEnding(const std::string &fullString, const std::string &ending);

void OpenFile(const std::string &filePath);
};

struct kernel_trace_t {
Expand Down