mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Driver: Block between read attempts
Driver: * Refactored to limit accessibility of member fields; Communication: * readTask() now calls for a blocking wait;
This commit is contained in:
committed by
Kyle Schwarz
parent
f25a0a4a81
commit
75af3220b0
+13
-11
@@ -11,13 +11,21 @@ using namespace icsneo;
|
||||
bool Driver::pushRx(const uint8_t* buf, size_t numReceived) {
|
||||
bool ret = readBuffer.write(buf, numReceived);
|
||||
|
||||
if(hasRxWaitRequest) {
|
||||
rxWaitRequestCv.notify_one();
|
||||
}
|
||||
rxWaitCv.notify_all();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Driver::clearBuffers()
|
||||
{
|
||||
WriteOperation flushop;
|
||||
|
||||
readBuffer.clear();
|
||||
rxWaitCv.notify_all();
|
||||
|
||||
while (writeQueue.try_dequeue(flushop)) {}
|
||||
}
|
||||
|
||||
bool Driver::waitForRx(size_t limit, std::chrono::milliseconds timeout) {
|
||||
return waitForRx([limit, this]() {
|
||||
return readBuffer.size() >= limit;
|
||||
@@ -26,13 +34,7 @@ bool Driver::waitForRx(size_t limit, std::chrono::milliseconds timeout) {
|
||||
|
||||
bool Driver::waitForRx(std::function<bool()> predicate, std::chrono::milliseconds timeout) {
|
||||
std::unique_lock<std::mutex> lk(rxWaitMutex);
|
||||
hasRxWaitRequest = true;
|
||||
|
||||
auto ret = rxWaitRequestCv.wait_for(lk, timeout, predicate);
|
||||
|
||||
hasRxWaitRequest = false;
|
||||
|
||||
return ret;
|
||||
return rxWaitCv.wait_for(lk, timeout, predicate);
|
||||
}
|
||||
|
||||
bool Driver::readWait(std::vector<uint8_t>& bytes, std::chrono::milliseconds timeout, size_t limit) {
|
||||
@@ -92,4 +94,4 @@ bool Driver::write(const std::vector<uint8_t>& bytes) {
|
||||
report(APIEvent::Type::Unknown, APIEvent::Severity::Error);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user