diff --git a/Makefile b/Makefile index 89b7b3bd9f077655d92ef9dc9ccb3024a40748af..c7f35af566bd3c0b40579ce67daa7682fcde070c 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 785f47067240b9b0a5e2d745e5a426777a7c58c1..98d26ac56cc283ecd85ae4309c3242123cc34698 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(); +// }