ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::ButtonEvent Class Reference

Thread-safe event wrapper for button IRQ notifications. More...

#include <button_event.hpp>

Collaboration diagram for c7222::ButtonEvent:
Collaboration graph

Public Member Functions

void SetEvents (std::uint32_t new_events)
 Set the event bitmask and notify waiters.
 
bool GetEvents (std::uint32_t timeout_ms, std::uint32_t &events_out)
 Wait for events with a timeout.
 

Detailed Description

Thread-safe event wrapper for button IRQ notifications.

Synchronization model and purpose:

  • Uses a std::mutex to protect the shared event state (events_ and event_ready_) from concurrent access by the ISR-dispatcher path and the consumer task.
  • Uses a std::condition_variable to block the consumer task efficiently until new events arrive, with optional timeout.
  • The flag event_ready_ is the condition predicate that prevents missed wake-ups (the consumer re-checks the flag after waking).
  • RAII is used for lock management inside GetEvents() via std::unique_lock, ensuring the mutex is released on all exit paths.
  • RAII is not used to represent the event itself because event ownership spans multiple threads and timeouts. The event is produced asynchronously (ISR-dispatcher path) and consumed later by a waiting task. An RAII guard would tie event lifetime to a single scope and thread, which is not appropriate for a cross-thread notification.

Intended usage:

  • SetEvents() is called by the IRQ dispatcher task or timer callback when a GPIO interrupt occurs.
  • GetEvents() is called by a consumer task that wants to wait for the next event without polling.

Member Function Documentation

◆ GetEvents()

bool c7222::ButtonEvent::GetEvents ( std::uint32_t  timeout_ms,
std::uint32_t &  events_out 
)

Wait for events with a timeout.

Parameters
timeout_msMaximum time to wait in milliseconds.
events_outFilled with event bitmask on success.
Returns
true if events were received, false on timeout.
Here is the caller graph for this function:

◆ SetEvents()

void c7222::ButtonEvent::SetEvents ( std::uint32_t  new_events)

Set the event bitmask and notify waiters.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: