Switches all notifiers created with the external API to be threaded (#546)

Testing showed this wasn't an issue with timing, and allows for more
safety in user code making mistakes. Places where the extra thread
wouldn't help have been kept non threaded, using a new internal API.
This commit is contained in:
Thad House
2017-06-30 18:58:58 -07:00
committed by Peter Johnson
parent 1d15fcd072
commit c57a7f0a41
5 changed files with 28 additions and 10 deletions

View File

@@ -17,6 +17,7 @@
#include "HAL/ChipObject.h"
#include "HAL/Errors.h"
#include "HAL/HAL.h"
#include "HAL/cpp/NotifierInternal.h"
#include "HAL/cpp/make_unique.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/UnlimitedHandleResource.h"
@@ -173,8 +174,8 @@ static void threadedNotifierHandler(uint64_t currentTimeInt,
extern "C" {
HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
void* param, int32_t* status) {
HAL_NotifierHandle HAL_InitializeNotifierNonThreadedUnsafe(
HAL_NotifierProcessFunction process, void* param, int32_t* status) {
if (!process) {
*status = NULL_PARAMETER;
return 0;
@@ -211,14 +212,14 @@ HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
return handle;
}
HAL_NotifierHandle HAL_InitializeNotifierThreaded(
HAL_NotifierProcessFunction process, void* param, int32_t* status) {
HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
void* param, int32_t* status) {
NotifierThreadOwner* notify = new NotifierThreadOwner;
notify->Start();
notify->SetFunc(process, param);
auto notifierHandle =
HAL_InitializeNotifier(threadedNotifierHandler, notify, status);
auto notifierHandle = HAL_InitializeNotifierNonThreadedUnsafe(
threadedNotifierHandler, notify, status);
if (notifierHandle == HAL_kInvalidHandle || *status != 0) {
delete notify;