WPILibC++ 2024.3.2
ListenerExecutor.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8#include <vector>
9
10#include <wpi/mutex.h>
11
12namespace frc::detail {
13/**
14 * An executor for running listener tasks posted by Sendable listeners
15 * synchronously from the main application thread.
16 *
17 * @see Sendable
18 */
20 public:
21 /**
22 * Posts a task to the executor to be run synchronously from the main thread.
23 *
24 * @param task The task to run synchronously from the main thread.
25 */
26 void Execute(std::function<void()> task);
27
28 /**
29 * Runs all posted tasks. Called periodically from main thread.
30 */
32
33 private:
34 std::vector<std::function<void()>> m_tasks;
35 std::vector<std::function<void()>> m_runningTasks;
36 wpi::mutex m_lock;
37};
38} // namespace frc::detail
An executor for running listener tasks posted by Sendable listeners synchronously from the main appli...
Definition: ListenerExecutor.h:19
void Execute(std::function< void()> task)
Posts a task to the executor to be run synchronously from the main thread.
void RunListenerTasks()
Runs all posted tasks.
Definition: RecordingController.h:19
::std::mutex mutex
Definition: mutex.h:17