diff --git a/hal/src/main/native/include/hal/Notifier.h b/hal/src/main/native/include/hal/Notifier.h index ce3dd7614e..62b6242cf3 100644 --- a/hal/src/main/native/include/hal/Notifier.h +++ b/hal/src/main/native/include/hal/Notifier.h @@ -6,6 +6,8 @@ #include +#include + #include "hal/Types.h" /** @@ -80,11 +82,14 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, * Waits for the next alarm for the specific notifier. * * This is a blocking call until either the time elapses or HAL_StopNotifier - * gets called. + * gets called. If the latter occurs, this function will return zero and any + * loops using this function should exit. Failing to do so can lead to + * use-after-frees. * * @param notifierHandle the notifier handle * @return the FPGA time the notifier returned */ +WPI_NODISCARD uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t* status); diff --git a/wpiutil/src/main/native/include/wpi/nodiscard.h b/wpiutil/src/main/native/include/wpi/nodiscard.h new file mode 100644 index 0000000000..d9240363bd --- /dev/null +++ b/wpiutil/src/main/native/include/wpi/nodiscard.h @@ -0,0 +1,21 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#ifndef WPIUTIL_WPI_NODISCARD_H_ +#define WPIUTIL_WPI_NODISCARD_H_ + +// This should only be used on APIs that can be compiled as C or C++. If the API +// is C++ only, use [[nodiscard]] instead. +#ifndef WPI_NODISCARD +#ifdef __cplusplus +#define WPI_NODISCARD [[nodiscard]] +#elif defined(__GNUC__) || defined(__llvm__) +#define WPI_NODISCARD __attribute__((warn_unused_result)) +#elif _MSC_VER +#define WPI_NODISCARD _Check_return_ +#endif + +#endif + +#endif // WPIUTIL_WPI_NODISCARD_H_