roo_transport
API Documentation for roo_transport
Loading...
Searching...
No Matches
outgoing_data_ready_notification.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef ROO_USE_THREADS
5
6#include "roo_threads.h"
7#include "roo_threads/condition_variable.h"
8#include "roo_threads/mutex.h"
9
10namespace roo_transport {
11namespace internal {
12
13class OutgoingDataReadyNotification {
14 public:
15 OutgoingDataReadyNotification() : mutex_(), has_data_to_send_(false), cv_() {}
16
17 void notify() {
18 roo::unique_lock<roo::mutex> guard(mutex_);
19 if (has_data_to_send_) return;
20 has_data_to_send_ = true;
21 // There is only one sender thread.
22 cv_.notify_one();
23 }
24
25 bool await(long micros) {
26 roo::unique_lock<roo::mutex> guard(mutex_);
27 bool result = cv_.wait_for(guard, roo_time::Micros(micros),
28 [this]() { return has_data_to_send_; });
29 has_data_to_send_ = false;
30 return result;
31 }
32
33 private:
34 roo::mutex mutex_;
35 bool has_data_to_send_;
36 roo::condition_variable cv_;
37};
38
39} // namespace internal
40} // namespace roo_transport
41
42#endif // ROO_USE_THREADS