Browse Source

back() and front() have defined behaviour now when queue is empty

ENGINE-781
Volker Birk 2 years ago
parent
commit
e658bbaf0e
2 changed files with 13 additions and 3 deletions
  1. +7
    -1
      Adapter.cc
  2. +6
    -2
      locked_queue.hh

+ 7
- 1
Adapter.cc View File

@ -147,7 +147,13 @@ namespace pEp {
bool in_shutdown()
{
SYNC_EVENT ev = q.back();
SYNC_EVENT ev;
try {
ev = q.back();
}
catch (std::underflow_error&) {
return false;
}
if (ev)
return false;
else


+ 6
- 2
locked_queue.hh View File

@ -38,17 +38,21 @@ namespace utility
_q.clear();
}
// undefined behavior when queue empty
// defined behavior when queue empty
T back()
{
Lock lg(_mtx);
if (_q.empty())
throw std::underflow_error("queue empty");
return _q.back();
}
// undefined behavior when queue empty
// defined behavior when queue empty
T front()
{
Lock lg(_mtx);
if (_q.empty())
throw std::underflow_error("queue empty");
return _q.front();
}


Loading…
Cancel
Save