From 4af3f2e5e87b397b3b135a03d87cb4bbcb00374d Mon Sep 17 00:00:00 2001 From: Terraneo Federico <fede.tft@miosix.org> Date: Sat, 7 Sep 2019 19:11:18 +0200 Subject: [PATCH] Miosix support for libatomic --- Makefile | 11 +++++-- .../libstdcpp_integration.cpp | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 89b7b3bd..c7f35af5 100644 --- a/Makefile +++ b/Makefile @@ -56,8 +56,15 @@ AFLAGS := $(AFLAGS_BASE) LFLAGS := $(LFLAGS_BASE) DFLAGS := -MMD -MP -LINK_LIBS := $(LIBS) -L$(KPATH) -Wl,--start-group -lmiosix -lstdc++ -lc \ - -lm -lgcc -Wl,--end-group +## libmiosix.a is among stdlibs because needs to be within start/end group +STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc + +GCCMAJOR := $(shell $(CC) --version | perl -e '$$_=<>;/\(GCC\) (\d+)/;print "$$1"') +ifneq ($(GCCMAJOR),4) + STDLIBS += -latomic +endif + +LINK_LIBS := $(LIBS) -L$(KPATH) -Wl,--start-group $(STDLIBS) -Wl,--end-group all: all-recursive main diff --git a/miosix/stdlib_integration/libstdcpp_integration.cpp b/miosix/stdlib_integration/libstdcpp_integration.cpp index 785f4706..98d26ac5 100644 --- a/miosix/stdlib_integration/libstdcpp_integration.cpp +++ b/miosix/stdlib_integration/libstdcpp_integration.cpp @@ -303,3 +303,33 @@ extern "C" void __cxa_guard_abort(__guard *g) noexcept } } //namespace __cxxabiv1 + +// +// libatomic support, to provide thread safe atomic operation fallbacks +// ==================================================================== + +// Not using the fast version, as these may be used before the kernel is started + +extern "C" unsigned int libat_quick_lock_n(void *ptr) +{ + miosix::disableInterrupts(); + return 0; +} + +extern "C" void libat_quick_unlock_n(void *ptr, unsigned int token) +{ + miosix::enableInterrupts(); +} + +// These are to implement "heavy" atomic operations, which are not used in +// libstdc++. For now let's keep them disbaled. + +// extern "C" void libat_lock_n(void *ptr, size_t n) +// { +// miosix::pauseKernel(); +// } +// +// extern "C" void libat_unlock_n(void *ptr, size_t n) +// { +// miosix::restartKernel(); +// } -- GitLab