Rename variable in parsebyparts
This commit is contained in:
parent
24d0ebd8fb
commit
dbe8d115b1
@ -17,7 +17,7 @@ using namespace rapidjson;
|
|||||||
template<unsigned parseFlags = kParseDefaultFlags>
|
template<unsigned parseFlags = kParseDefaultFlags>
|
||||||
class AsyncDocumentParser {
|
class AsyncDocumentParser {
|
||||||
public:
|
public:
|
||||||
AsyncDocumentParser(Document& d) : ass_(*this), d_(d), parseThread_(&AsyncDocumentParser::Parse, this), completed_() {}
|
AsyncDocumentParser(Document& d) : stream_(*this), d_(d), parseThread_(&AsyncDocumentParser::Parse, this), completed_() {}
|
||||||
|
|
||||||
~AsyncDocumentParser() {
|
~AsyncDocumentParser() {
|
||||||
if (!parseThread_.joinable())
|
if (!parseThread_.joinable())
|
||||||
@ -27,13 +27,13 @@ public:
|
|||||||
std::unique_lock<std::mutex> lock(mutex_);
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
// Wait until the buffer is read up (or parsing is completed)
|
// Wait until the buffer is read up (or parsing is completed)
|
||||||
while (!ass_.Empty() && !completed_)
|
while (!stream_.Empty() && !completed_)
|
||||||
finish_.wait(lock);
|
finish_.wait(lock);
|
||||||
|
|
||||||
// Automatically append '\0' as the terminator in the stream.
|
// Automatically append '\0' as the terminator in the stream.
|
||||||
static const char terminator[] = "";
|
static const char terminator[] = "";
|
||||||
ass_.src_ = terminator;
|
stream_.src_ = terminator;
|
||||||
ass_.end_ = terminator + 1;
|
stream_.end_ = terminator + 1;
|
||||||
notEmpty_.notify_one(); // unblock the AsyncStringStream
|
notEmpty_.notify_one(); // unblock the AsyncStringStream
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public:
|
|||||||
std::unique_lock<std::mutex> lock(mutex_);
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
// Wait until the buffer is read up (or parsing is completed)
|
// Wait until the buffer is read up (or parsing is completed)
|
||||||
while (!ass_.Empty() && !completed_)
|
while (!stream_.Empty() && !completed_)
|
||||||
finish_.wait(lock);
|
finish_.wait(lock);
|
||||||
|
|
||||||
// Stop further parsing if the parsing process is completed.
|
// Stop further parsing if the parsing process is completed.
|
||||||
@ -52,14 +52,14 @@ public:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Set the buffer to stream and unblock the AsyncStringStream
|
// Set the buffer to stream and unblock the AsyncStringStream
|
||||||
ass_.src_ = buffer;
|
stream_.src_ = buffer;
|
||||||
ass_.end_ = buffer + length;
|
stream_.end_ = buffer + length;
|
||||||
notEmpty_.notify_one();
|
notEmpty_.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Parse() {
|
void Parse() {
|
||||||
d_.ParseStream<parseFlags>(ass_);
|
d_.ParseStream<parseFlags>(stream_);
|
||||||
|
|
||||||
// The stream may not be fully read, notify finish anyway to unblock ParsePart()
|
// The stream may not be fully read, notify finish anyway to unblock ParsePart()
|
||||||
std::unique_lock<std::mutex> lock(mutex_);
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
@ -115,7 +115,7 @@ private:
|
|||||||
size_t count_; //!< Number of characters taken so far.
|
size_t count_; //!< Number of characters taken so far.
|
||||||
};
|
};
|
||||||
|
|
||||||
AsyncStringStream ass_;
|
AsyncStringStream stream_;
|
||||||
Document& d_;
|
Document& d_;
|
||||||
std::thread parseThread_;
|
std::thread parseThread_;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user