From ba445c6c0d97f61bfe2447cebf48b3d26fe28b58 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Jun 2019 12:51:27 +0200 Subject: [PATCH] Compilation fix on OSX / Windows --- companion/src/storage/mountlist.cpp | 2 +- radio/src/rtos.h | 16 +++++++++++----- radio/src/targets/simu/simpgmspace.cpp | 2 ++ radio/src/targets/simu/simueeprom.cpp | 13 +++++-------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/companion/src/storage/mountlist.cpp b/companion/src/storage/mountlist.cpp index aa52c1afc..d40339c1c 100644 --- a/companion/src/storage/mountlist.cpp +++ b/companion/src/storage/mountlist.cpp @@ -363,7 +363,7 @@ dev_from_mount_options (char const *mount_options) /* GNU/Linux allows file system implementations to define their own meaning for "dev=" mount options, so don't trust the meaning here. */ -# ifndef __linux__ +#ifndef __linux__ static char const dev_pattern[] = ",dev="; char const *devopt = strstr (mount_options, dev_pattern); diff --git a/radio/src/rtos.h b/radio/src/rtos.h index b439ecea6..6e42ebf30 100644 --- a/radio/src/rtos.h +++ b/radio/src/rtos.h @@ -28,7 +28,6 @@ extern "C++" { #endif #if defined(SIMU) - #include #include @@ -113,11 +112,20 @@ extern "C++" { #define TASK_FUNCTION(task) void * task(void * pdata) - template - inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char * name, FakeTaskStack &, unsigned, unsigned) + inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char * name) { pthread_create(&taskId, nullptr, task, nullptr); +#ifdef __linux__ pthread_setname_np(taskId, name); +#endif + } + +template + inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char * name, FakeTaskStack &, unsigned size = 0, unsigned priority = 0) + { + UNUSED(size); + UNUSED(priority); + RTOS_CREATE_TASK(taskId, task, name); } #define TASK_RETURN() return nullptr @@ -138,9 +146,7 @@ extern "C++" { { return (uint32_t)(simuTimerMicros() / 1000); } - #elif defined(RTOS_COOS) - #ifdef __cplusplus extern "C" { #endif diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index d93ee21c6..9a6fa552b 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -386,7 +386,9 @@ void StartAudioThread(int volumeGain) sp.sched_priority = SCHED_RR; pthread_attr_setschedparam(&attr, &sp); pthread_create(&simuAudio.threadPid, &attr, &audioThread, nullptr); +#ifdef __linux__ pthread_setname_np(simuAudio.threadPid, "audio"); +#endif return; } diff --git a/radio/src/targets/simu/simueeprom.cpp b/radio/src/targets/simu/simueeprom.cpp index d2368c7c0..414b73270 100644 --- a/radio/src/targets/simu/simueeprom.cpp +++ b/radio/src/targets/simu/simueeprom.cpp @@ -73,6 +73,8 @@ void eepromSimuWriteBlock(uint8_t * buffer, size_t address, size_t size) volatile uint8_t eepromTransferComplete = 1; void * eeprom_thread_function(void *) { + eeprom_thread_running = true; + while (!sem_wait(eeprom_write_sem)) { if (!eeprom_thread_running) return nullptr; @@ -85,7 +87,8 @@ void * eeprom_thread_function(void *) } eepromTransferComplete = 1; } - return 0; + + return nullptr; } uint8_t eepromReadStatus() @@ -162,13 +165,7 @@ void StartEepromThread(const char * filename) sem_init(eeprom_write_sem, 0, 0); #endif - if (!pthread_create(&eeprom_thread_pid, nullptr, &eeprom_thread_function, nullptr)) { - pthread_setname_np(eeprom_thread_pid, "eeprom"); - eeprom_thread_running = true; - } - else { - perror("Could not create eeprom thread."); - } + RTOS_CREATE_TASK(eeprom_thread_pid, eeprom_thread_function, "eeprom"); } void StopEepromThread()