Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 1 | #ifndef AOS_EVENTS_EVENT_LOOP_TMPL_H_ |
| 2 | #define AOS_EVENTS_EVENT_LOOP_TMPL_H_ |
| 3 | |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 4 | #include <inttypes.h> |
| 5 | #include <stdint.h> |
| 6 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 7 | #include <type_traits> |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 8 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 9 | #include "aos/events/event_loop.h" |
| 10 | #include "glog/logging.h" |
| 11 | |
| 12 | namespace aos { |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 13 | namespace event_loop_internal { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 14 | |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 15 | // From a watch functor, specializations of this will extract the message type |
| 16 | // of the template argument. If T is not a valid message type, there will be no |
| 17 | // matching specialization. |
| 18 | // |
| 19 | // This is just the forward declaration, which will be used by one of the |
| 20 | // following specializations to match valid argument types. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 21 | template <class T> |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 22 | struct watch_message_type_trait; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 23 | |
| 24 | // From a watch functor, this will extract the message type of the argument. |
| 25 | // This is the template specialization. |
| 26 | template <class ClassType, class ReturnType, class A1> |
| 27 | struct watch_message_type_trait<ReturnType (ClassType::*)(A1) const> { |
| 28 | using message_type = typename std::decay<A1>::type; |
| 29 | }; |
| 30 | |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 31 | } // namespace event_loop_internal |
| 32 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 33 | template <typename T> |
| 34 | typename Sender<T>::Builder Sender<T>::MakeBuilder() { |
Brian Silverman | a1652f3 | 2020-01-29 20:41:44 -0800 | [diff] [blame] | 35 | return Builder(sender_.get(), sender_->fbb_allocator()); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | template <typename Watch> |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 39 | void EventLoop::MakeWatcher(const std::string_view channel_name, Watch &&w) { |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 40 | using MessageType = |
| 41 | typename event_loop_internal::watch_message_type_trait<decltype( |
| 42 | &Watch::operator())>::message_type; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 43 | const Channel *channel = configuration::GetChannel( |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 44 | configuration_, channel_name, MessageType::GetFullyQualifiedName(), |
| 45 | name(), node()); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 46 | |
| 47 | CHECK(channel != nullptr) |
| 48 | << ": Channel { \"name\": \"" << channel_name << "\", \"type\": \"" |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 49 | << MessageType::GetFullyQualifiedName() << "\" } not found in config."; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 50 | |
Brian Silverman | 454bc11 | 2020-03-05 14:21:25 -0800 | [diff] [blame] | 51 | MakeRawWatcher(channel, |
| 52 | [this, w](const Context &context, const void *message) { |
| 53 | context_ = context; |
| 54 | w(*flatbuffers::GetRoot<MessageType>( |
| 55 | reinterpret_cast<const char *>(message))); |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | template <typename MessageType> |
| 60 | void EventLoop::MakeNoArgWatcher(const std::string_view channel_name, |
| 61 | std::function<void()> w) { |
| 62 | const Channel *channel = configuration::GetChannel( |
| 63 | configuration_, channel_name, MessageType::GetFullyQualifiedName(), |
| 64 | name(), node()); |
| 65 | CHECK(channel != nullptr) |
| 66 | << ": Channel { \"name\": \"" << channel_name << "\", \"type\": \"" |
| 67 | << MessageType::GetFullyQualifiedName() << "\" } not found in config."; |
| 68 | MakeRawNoArgWatcher(channel, [this, w](const Context &context) { |
| 69 | context_ = context; |
| 70 | w(); |
| 71 | }); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 74 | inline bool RawFetcher::FetchNext() { |
| 75 | const auto result = DoFetchNext(); |
| 76 | if (result.first) { |
| 77 | timing_.fetcher->mutate_count(timing_.fetcher->count() + 1); |
| 78 | const monotonic_clock::time_point monotonic_time = result.second; |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 79 | ftrace_.FormatMessage( |
| 80 | "%.*s: fetch next: now=%" PRId64 " event=%" PRId64 " queue=%" PRIu32, |
| 81 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 82 | static_cast<int64_t>(monotonic_time.time_since_epoch().count()), |
| 83 | static_cast<int64_t>( |
| 84 | context_.monotonic_event_time.time_since_epoch().count()), |
| 85 | context_.queue_index); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 86 | const float latency = |
| 87 | std::chrono::duration_cast<std::chrono::duration<float>>( |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 88 | monotonic_time - context_.monotonic_event_time) |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 89 | .count(); |
| 90 | timing_.latency.Add(latency); |
| 91 | return true; |
| 92 | } |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 93 | ftrace_.FormatMessage( |
| 94 | "%.*s: fetch next: still event=%" PRId64 " queue=%" PRIu32, |
| 95 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 96 | static_cast<int64_t>( |
| 97 | context_.monotonic_event_time.time_since_epoch().count()), |
| 98 | context_.queue_index); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | |
| 102 | inline bool RawFetcher::Fetch() { |
| 103 | const auto result = DoFetch(); |
| 104 | if (result.first) { |
| 105 | timing_.fetcher->mutate_count(timing_.fetcher->count() + 1); |
| 106 | const monotonic_clock::time_point monotonic_time = result.second; |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 107 | ftrace_.FormatMessage( |
| 108 | "%.*s: fetch latest: now=%" PRId64 " event=%" PRId64 " queue=%" PRIu32, |
| 109 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 110 | static_cast<int64_t>(monotonic_time.time_since_epoch().count()), |
| 111 | static_cast<int64_t>( |
| 112 | context_.monotonic_event_time.time_since_epoch().count()), |
| 113 | context_.queue_index); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 114 | const float latency = |
| 115 | std::chrono::duration_cast<std::chrono::duration<float>>( |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 116 | monotonic_time - context_.monotonic_event_time) |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 117 | .count(); |
| 118 | timing_.latency.Add(latency); |
| 119 | return true; |
| 120 | } |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 121 | ftrace_.FormatMessage( |
| 122 | "%.*s: fetch latest: still event=%" PRId64 " queue=%" PRIu32, |
| 123 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 124 | static_cast<int64_t>( |
| 125 | context_.monotonic_event_time.time_since_epoch().count()), |
| 126 | context_.queue_index); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 127 | return false; |
| 128 | } |
| 129 | |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 130 | inline bool RawSender::Send( |
| 131 | size_t size, aos::monotonic_clock::time_point monotonic_remote_time, |
| 132 | aos::realtime_clock::time_point realtime_remote_time, |
| 133 | uint32_t remote_queue_index) { |
| 134 | if (DoSend(size, monotonic_remote_time, realtime_remote_time, |
| 135 | remote_queue_index)) { |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 136 | timing_.size.Add(size); |
| 137 | timing_.sender->mutate_count(timing_.sender->count() + 1); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 138 | ftrace_.FormatMessage( |
| 139 | "%.*s: sent internal: event=%" PRId64 " queue=%" PRIu32, |
| 140 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 141 | static_cast<int64_t>(monotonic_sent_time().time_since_epoch().count()), |
| 142 | sent_queue_index()); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 143 | return true; |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 148 | inline bool RawSender::Send( |
| 149 | const void *data, size_t size, |
| 150 | aos::monotonic_clock::time_point monotonic_remote_time, |
| 151 | aos::realtime_clock::time_point realtime_remote_time, |
| 152 | uint32_t remote_queue_index) { |
| 153 | if (DoSend(data, size, monotonic_remote_time, realtime_remote_time, |
| 154 | remote_queue_index)) { |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 155 | timing_.size.Add(size); |
| 156 | timing_.sender->mutate_count(timing_.sender->count() + 1); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 157 | ftrace_.FormatMessage( |
| 158 | "%.*s: sent external: event=%" PRId64 " queue=%" PRIu32, |
| 159 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 160 | static_cast<int64_t>(monotonic_sent_time().time_since_epoch().count()), |
| 161 | sent_queue_index()); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 162 | return true; |
| 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | |
Austin Schuh | cde39fd | 2020-02-22 20:58:24 -0800 | [diff] [blame] | 167 | inline monotonic_clock::time_point TimerHandler::Call( |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 168 | std::function<monotonic_clock::time_point()> get_time, |
| 169 | monotonic_clock::time_point event_time) { |
| 170 | CHECK_NOTNULL(timing_.timer); |
| 171 | const monotonic_clock::time_point monotonic_start_time = get_time(); |
| 172 | |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 173 | event_loop_->context_.monotonic_event_time = event_time; |
| 174 | event_loop_->context_.monotonic_remote_time = monotonic_clock::min_time; |
| 175 | event_loop_->context_.realtime_remote_time = |
| 176 | event_loop_->context_.realtime_event_time = realtime_clock::min_time; |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 177 | event_loop_->context_.queue_index = 0xffffffffu; |
| 178 | event_loop_->context_.size = 0; |
| 179 | event_loop_->context_.data = nullptr; |
| 180 | |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 181 | ftrace_.FormatMessage( |
| 182 | "timer: %.*s: start now=%" PRId64 " event=%" PRId64, |
| 183 | static_cast<int>(name_.size()), name_.data(), |
| 184 | static_cast<int64_t>(monotonic_start_time.time_since_epoch().count()), |
| 185 | static_cast<int64_t>(event_time.time_since_epoch().count())); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 186 | { |
| 187 | const float start_latency = |
| 188 | std::chrono::duration_cast<std::chrono::duration<float>>( |
| 189 | monotonic_start_time - event_time) |
| 190 | .count(); |
| 191 | timing_.wakeup_latency.Add(start_latency); |
| 192 | } |
| 193 | timing_.timer->mutate_count(timing_.timer->count() + 1); |
| 194 | fn_(); |
| 195 | |
| 196 | const monotonic_clock::time_point monotonic_end_time = get_time(); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 197 | ftrace_.FormatMessage( |
| 198 | "timer: %.*s: end now=%" PRId64, static_cast<int>(name_.size()), |
| 199 | name_.data(), |
| 200 | static_cast<int64_t>(monotonic_end_time.time_since_epoch().count())); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 201 | |
| 202 | const float handler_latency = |
| 203 | std::chrono::duration_cast<std::chrono::duration<float>>( |
| 204 | monotonic_end_time - monotonic_start_time) |
| 205 | .count(); |
| 206 | timing_.handler_time.Add(handler_latency); |
Austin Schuh | cde39fd | 2020-02-22 20:58:24 -0800 | [diff] [blame] | 207 | return monotonic_start_time; |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | inline void PhasedLoopHandler::Call( |
| 211 | std::function<monotonic_clock::time_point()> get_time, |
| 212 | std::function<void(monotonic_clock::time_point)> schedule) { |
| 213 | // Read time directly to save a vtable indirection... |
| 214 | const monotonic_clock::time_point monotonic_start_time = get_time(); |
| 215 | |
| 216 | // Update the context to hold the desired wakeup time. |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 217 | event_loop_->context_.monotonic_event_time = phased_loop_.sleep_time(); |
| 218 | event_loop_->context_.monotonic_remote_time = monotonic_clock::min_time; |
| 219 | event_loop_->context_.realtime_remote_time = |
| 220 | event_loop_->context_.realtime_event_time = realtime_clock::min_time; |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 221 | event_loop_->context_.queue_index = 0xffffffffu; |
| 222 | event_loop_->context_.size = 0; |
| 223 | event_loop_->context_.data = nullptr; |
| 224 | |
| 225 | // Compute how many cycles elapsed and schedule the next wakeup. |
| 226 | Reschedule(schedule, monotonic_start_time); |
| 227 | |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 228 | ftrace_.FormatMessage( |
| 229 | "phased: %.*s: start now=%" PRId64 " event=%" PRId64 " cycles=%d", |
| 230 | static_cast<int>(name_.size()), name_.data(), |
| 231 | static_cast<int64_t>(monotonic_start_time.time_since_epoch().count()), |
| 232 | static_cast<int64_t>( |
| 233 | phased_loop_.sleep_time().time_since_epoch().count()), |
| 234 | cycles_elapsed_); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 235 | { |
| 236 | const float start_latency = |
| 237 | std::chrono::duration_cast<std::chrono::duration<float>>( |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 238 | monotonic_start_time - event_loop_->context_.monotonic_event_time) |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 239 | .count(); |
| 240 | timing_.wakeup_latency.Add(start_latency); |
| 241 | } |
| 242 | timing_.timer->mutate_count(timing_.timer->count() + 1); |
| 243 | |
| 244 | // Call the function with the elapsed cycles. |
| 245 | fn_(cycles_elapsed_); |
| 246 | cycles_elapsed_ = 0; |
| 247 | |
| 248 | const monotonic_clock::time_point monotonic_end_time = get_time(); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 249 | ftrace_.FormatMessage( |
| 250 | "phased: %.*s: end now=%" PRId64, static_cast<int>(name_.size()), |
| 251 | name_.data(), |
| 252 | static_cast<int64_t>(monotonic_end_time.time_since_epoch().count())); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 253 | |
| 254 | const float handler_latency = |
| 255 | std::chrono::duration_cast<std::chrono::duration<float>>( |
| 256 | monotonic_end_time - monotonic_start_time) |
| 257 | .count(); |
| 258 | timing_.handler_time.Add(handler_latency); |
| 259 | |
| 260 | // If the handler too too long so we blew by the previous deadline, we |
| 261 | // want to just try for the next deadline. Rescuedule. |
| 262 | if (monotonic_end_time > phased_loop_.sleep_time()) { |
| 263 | Reschedule(schedule, monotonic_end_time); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Class to automate the timing report generation for watchers. |
| 268 | class WatcherState { |
| 269 | public: |
| 270 | WatcherState( |
| 271 | EventLoop *event_loop, const Channel *channel, |
| 272 | std::function<void(const Context &context, const void *message)> fn) |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 273 | : channel_index_(event_loop->ChannelIndex(channel)), |
| 274 | ftrace_prefix_(configuration::StrippedChannelToString(channel)), |
| 275 | fn_(std::move(fn)) {} |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 276 | |
| 277 | virtual ~WatcherState() {} |
| 278 | |
| 279 | // Calls the callback, measuring time with get_time, with the provided |
| 280 | // context. |
| 281 | void DoCallCallback(std::function<monotonic_clock::time_point()> get_time, |
| 282 | Context context) { |
Brian Silverman | 6b8a3c3 | 2020-03-06 11:26:14 -0800 | [diff] [blame] | 283 | if (context.data) { |
| 284 | CheckChannelDataAlignment(context.data, context.size); |
| 285 | } |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 286 | const monotonic_clock::time_point monotonic_start_time = get_time(); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 287 | ftrace_.FormatMessage( |
| 288 | "%.*s: watcher start: now=%" PRId64 " event=%" PRId64 " queue=%" PRIu32, |
| 289 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 290 | static_cast<int64_t>(monotonic_start_time.time_since_epoch().count()), |
| 291 | static_cast<int64_t>( |
| 292 | context.monotonic_event_time.time_since_epoch().count()), |
| 293 | context.queue_index); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 294 | { |
| 295 | const float start_latency = |
| 296 | std::chrono::duration_cast<std::chrono::duration<float>>( |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 297 | monotonic_start_time - context.monotonic_event_time) |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 298 | .count(); |
| 299 | wakeup_latency_.Add(start_latency); |
| 300 | } |
| 301 | watcher_->mutate_count(watcher_->count() + 1); |
| 302 | fn_(context, context.data); |
| 303 | |
| 304 | const monotonic_clock::time_point monotonic_end_time = get_time(); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 305 | ftrace_.FormatMessage( |
| 306 | "%.*s: watcher end: now=%" PRId64, |
| 307 | static_cast<int>(ftrace_prefix_.size()), ftrace_prefix_.data(), |
| 308 | static_cast<int64_t>(monotonic_end_time.time_since_epoch().count())); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 309 | |
| 310 | const float handler_latency = |
| 311 | std::chrono::duration_cast<std::chrono::duration<float>>( |
| 312 | monotonic_end_time - monotonic_start_time) |
| 313 | .count(); |
| 314 | handler_time_.Add(handler_latency); |
| 315 | } |
| 316 | |
| 317 | int channel_index() const { return channel_index_; } |
| 318 | |
| 319 | void set_timing_report(timing::Watcher *watcher); |
| 320 | void ResetReport(); |
| 321 | |
| 322 | virtual void Startup(EventLoop *event_loop) = 0; |
| 323 | |
| 324 | protected: |
| 325 | const int channel_index_; |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 326 | const std::string ftrace_prefix_; |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 327 | |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 328 | const std::function<void(const Context &context, const void *message)> fn_; |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 329 | |
| 330 | internal::TimingStatistic wakeup_latency_; |
| 331 | internal::TimingStatistic handler_time_; |
| 332 | timing::Watcher *watcher_ = nullptr; |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 333 | |
| 334 | Ftrace ftrace_; |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 335 | }; |
| 336 | |
Austin Schuh | a28cbc3 | 2019-12-27 16:28:04 -0800 | [diff] [blame] | 337 | template <typename T> |
| 338 | bool Sender<T>::Send(const Flatbuffer<T> &flatbuffer) { |
| 339 | return sender_->Send(flatbuffer.data(), flatbuffer.size()); |
| 340 | } |
| 341 | |
Brian Silverman | 341b57e | 2020-06-23 16:23:18 -0700 | [diff] [blame^] | 342 | template <typename T> |
| 343 | bool Sender<T>::SendDetached(FlatbufferDetachedBuffer<T> detached) { |
| 344 | CHECK_EQ( |
| 345 | static_cast<void *>(detached.data() + detached.size() - sender_->size()), |
| 346 | sender_->data()) |
| 347 | << ": May only send the buffer detached from this Sender"; |
| 348 | return sender_->Send(detached.size()); |
| 349 | } |
| 350 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 351 | } // namespace aos |
| 352 | |
| 353 | #endif // AOS_EVENTS_EVENT_LOOP_TMPL_H |