diff options
author | Chienyuan <chienyuanhuang@google.com> | 2019-04-30 16:21:32 -0700 |
---|---|---|
committer | Hansong Zhang <hsz@google.com> | 2019-05-01 12:12:35 -0700 |
commit | 89430fe73d7d40f3429bd440b9ea0bcfd0c35237 (patch) | |
tree | 7615ffeae7d55106433ffd474643c5a9ae566aa5 /gd/common | |
parent | 5158bf5eeb673eafa75f1ab8422063a47fa3633b (diff) | |
download | bt-89430fe73d7d40f3429bd440b9ea0bcfd0c35237.tar.gz |
Cert: add common helper for event stream on the py side
* add common helper for event stream on the py side, implement
assert_event_occurs in the helper
* add event stream helpers for hci event, sco and acl in GdDevice
* add take_for() function in BlockingQueue for take data with timeout
Test: run gd/cert/run_cert.sh
Change-Id: Ia8168159ee47441ec332046627124e0ed3811d6b
Diffstat (limited to 'gd/common')
-rw-r--r-- | gd/common/blocking_queue.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gd/common/blocking_queue.h b/gd/common/blocking_queue.h index 0fbabc902..8d006d5d7 100644 --- a/gd/common/blocking_queue.h +++ b/gd/common/blocking_queue.h @@ -16,6 +16,7 @@ #pragma once +#include <chrono> #include <condition_variable> #include <mutex> #include <queue> @@ -44,6 +45,19 @@ class BlockingQueue { return data; }; + bool take_for(std::chrono::milliseconds time, T& data) { + std::unique_lock<std::mutex> lock(mutex_); + while (queue_.empty()) { + if (not_empty_.wait_for(lock, time) == std::cv_status::timeout) { + return false; + } + } + data = queue_.front(); + queue_.pop(); + + return true; + } + bool empty() const { std::unique_lock<std::mutex> lock(mutex_); return queue_.empty(); |