Skip to content

Commit

Permalink
Part of theheraldproject#98. Related to theheraldproject#105. Removed…
Browse files Browse the repository at this point in the history
… throw clauses on Zephyr.

Removed throw clauses via ifdef if compiled on zephyr
- Uses std::terminate instead
- Did not save any SRAM on its own (See stdlib terminate definition)
Signed-off-by: Adam Fowler <adam@adamfowler.org>
  • Loading branch information
adamfowleruk committed Sep 5, 2021
1 parent e4c732f commit a7f3286
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions herald-wearable/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Wearable specific settings (see config/zephyr/base.conf et al for mixed-in settings)
CONFIG_BT_DEVICE_NAME="Herald Wearable"

# Analysis engine uses variant, and so can have (an extremely hard to create) invalid variant exception
CONFIG_EXCEPTIONS=y
# Analysis engine uses variant, and so can have (an extremely hard to create) invalid variant exception -> Note: Switched now to std::terminate instead if zephyr detected
CONFIG_EXCEPTIONS=n
# CONFIG_HW_STACK_PROTECTION=y

# REQUIRED if using DEBUG mode in wearable sample only
Expand Down
12 changes: 12 additions & 0 deletions herald/include/herald/analysis/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ struct VariantSet {
return *pval;
}
}
#ifdef __ZEPHYR__
std::terminate();
#else
throw std::bad_variant_access();
#endif
}

const std::size_t size() const {
Expand Down Expand Up @@ -128,7 +132,11 @@ struct AnalysisDelegateManager {
return *pval;
}
}
#ifdef __ZEPHYR__
std::terminate();
#else
throw std::bad_variant_access();
#endif
}

private:
Expand Down Expand Up @@ -181,7 +189,11 @@ struct AnalysisProviderManager {
return *pval;
}
}
#ifdef __ZEPHYR__
std::terminate();
#else
throw std::bad_variant_access();
#endif
}

template <typename InputT,typename OutputT>
Expand Down
18 changes: 11 additions & 7 deletions herald/include/herald/datatype/memory_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class MemoryArena {
;
}

~MemoryArena() = default;
~MemoryArena() noexcept = default;

void reserve(MemoryArenaEntry& entry,std::size_t newSize) {
void reserve(MemoryArenaEntry& entry,std::size_t newSize) noexcept {
if (newSize <= entry.byteLength) {
return;
}
Expand Down Expand Up @@ -92,10 +92,14 @@ class MemoryArena {
}
}
// ran out of memory! Throw! (Causes catastrophic crash)
#ifdef __ZEPHYR__
std::terminate();
#else
throw std::runtime_error("Unable to allocate memory in arena");
#endif
}

void deallocate(MemoryArenaEntry& entry) {
void deallocate(MemoryArenaEntry& entry) noexcept {
if (!entry.isInitialised()) {
return; // guard
}
Expand All @@ -108,29 +112,29 @@ class MemoryArena {
entry.startPageIndex = 0;
}

void set(const MemoryArenaEntry& entry, unsigned short bytePosition, unsigned char value) {
void set(const MemoryArenaEntry& entry, unsigned short bytePosition, unsigned char value) noexcept {
if (!entry.isInitialised()) {
return;
}
arena[(entry.startPageIndex * PageSize) + bytePosition] = value;
}

char get(const MemoryArenaEntry& entry, unsigned short bytePosition) {
char get(const MemoryArenaEntry& entry, unsigned short bytePosition) noexcept {
if (!entry.isInitialised()) {
return '\0';
}
return arena[(entry.startPageIndex * PageSize) + bytePosition];
}

unsigned char* rawStartAddress(const MemoryArenaEntry& entry) {
unsigned char* rawStartAddress(const MemoryArenaEntry& entry) noexcept {
if (!entry.isInitialised()) {
return 0;
}
// The following is guaranteed by the STL 23.3.2.1
return &arena[(entry.startPageIndex * PageSize)];
}

std::size_t pagesFree() const {
std::size_t pagesFree() const noexcept {
return pagesRequired(Size,PageSize) - pagesInUse.count();
}

Expand Down

0 comments on commit a7f3286

Please sign in to comment.