Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Corbelli committed Aug 22, 2017
1 parent ddab43e commit 9490919
Show file tree
Hide file tree
Showing 8 changed files with 4,251 additions and 0 deletions.
116 changes: 116 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Percorsi di ricerca
vpath %.cpp src
vpath %.h include
vpath %.h include/rtlog

TOOLCHAIN_ROOT = /opt/OSELAS.Toolchain-2012.12.0
GCCFILTER = /home/corbelli/devel/gccfilter --remove-path
CROSS_COMPILE =
# GCCFILTER =

AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(GCCFILTER) $(CROSS_COMPILE)gcc
CXX = $(GCCFILTER) $(CROSS_COMPILE)g++
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump

INCLUDE := \
-Iinclude/stdafx.h.gch \
-I/usr/include/boost \
-I/home/corbelli/devel/fmt

LFLAGS := \
-L/home/corbelli/devel/fmt/build/fmt

LFLAGSD :=
MAKEOPTS :=
LIBS := -lfmt
LIBSD :=

WARNINGS := -Winvalid-pch -Wno-unknown-pragmas -Wall
WARNINGSD := -Winvalid-pch -Wno-unknown-pragmas -Wall
DEFINES := -D_MT -DNDEBUG
DEFINESD :=
CFLAGS := -pthread -fno-strict-aliasing -fwrapv -fexceptions -fPIC -O2 -pipe -g $(WARNINGS) -Wstrict-prototypes $(DEFINES) $(INCLUDE)
CFLAGSD := -pthread -fno-strict-aliasing -fwrapv -fexceptions -fPIC -O2 -pipe -ggdb $(WARNINGSD) -Wstrict-prototypes $(DEFINESD) $(INCLUDE)
CXXFLAGS := -pthread -std=c++11 -fno-strict-aliasing -fwrapv -fexceptions -fPIC -O2 -pipe -g $(WARNINGS) $(DEFINES) $(INCLUDE)
#Si potrebbe usare -D_GLIBCXX_DEBUG ma vanno compilate così anche tutte le librerie
#CXXFLAGSD := -Winvalid-pch -O2 -Wall -pipe -ggdb -D_MT -DDEBUG -DBUILDING_DLL -D_GLIBCXX_DEBUG -fPIC $(INCLUDE)
CXXFLAGSD := -pthread -fno-strict-aliasing -fwrapv -fexceptions -fPIC -O2 -pipe -ggdb $(WARNINGSD) $(DEFINESD) $(INCLUDE)

ARCH := $(shell uname -m)
BINDIR := bin
INCDIR := include
SRCDIR := src
STDAFXDIR := include/stdafx.h.gch
OBJDIR := $(BINDIR)/$(ARCH)
OBJDIRD := $(BINDIR)/$(ARCH)d

#Il file stdafx.cpp e' usato solo con MSVC
lib_sources := $(shell ls -t src/|grep -v stdafx|grep cpp | sed -e 's/src\///')
lib_objects := $(lib_sources:%.cpp=$(OBJDIR)/%.o)
lib_objectsd := $(lib_sources:%.cpp=$(OBJDIRD)/%.o)

sharedLib = $(BINDIR)/libCopanC.so
sharedLibD = $(BINDIR)/libCopanC-d.so
staticLib = $(BINDIR)/libCopanC.a
staticLibD = $(BINDIR)/libCopanC-d.a
gchIncludeD = $(INCDIR)/stdafx.h.gch

.PHONY: all debug static static-debug setup clean distclean

all: setup test
debug: setupd
static: setup_static
static-debug: setupd_static

setup:
mkdir -p $(OBJDIR)
mkdir -p $(STDAFXDIR)
setupd:
mkdir -p $(OBJDIRD)
mkdir -p $(STDAFXDIR)

setup_static: setup
setupd_static: setupd

clean: setup setupd
$(RM) $(OBJDIR)/* $(OBJDIRD)/* $(sharedLib) $(sharedLibD) $(staticLib) $(staticLibD) $(gchIncludeD)/*

distclean: clean
$(RM) -rf $(STDAFXDIR)

test: $(OBJDIR)/test.o
$(CXX) $(CXXFLAGS) $(LFLAGS) -o $@ $(OBJDIR)/test.o $(LIBS)

#~ $(sharedLib): override CXXFLAGS += -DBUILDING_DLL
#~ $(sharedLib): $(lib_objects)
#~ $(CXX) $(CXXFLAGS) $(LFLAGS) -shared -o $@ $(lib_objects) $(LIBS)

#~ $(sharedLibD): override CXXFLAGSD += -DBUILDING_DLL
#~ $(sharedLibD): $(lib_objectsd)
#~ $(CXX) $(CXXFLAGSD) $(LFLAGSD) -shared -o $@ $(lib_objectsd) $(LIBSD)

#~ $(staticLib): $(lib_objects)
#~ $(AR) crv $@ $(lib_objects)

#~ $(staticLibD): $(lib_objectsd)
#~ $(AR) crv $@ $(lib_objectsd)

# Precompiled headers
$(STDAFXDIR)/stdafx.h.gch: $(INCDIR)/stdafx.h
$(CXX) $(CXXFLAGS) -x c++-header $(INCDIR)/stdafx.h -o $@
$(STDAFXDIR)/stdafx.h.gchd: $(INCDIR)/stdafx.h
$(CXX) $(CXXFLAGSD) -x c++-header $(INCDIR)/stdafx.h -o $@

#Il primo prerequisito sono i pch, quindi non posso usare $<
#$^ sono TUTTI i prerequisiti, in questo caso il file .cpp e' la seconda parola
$(OBJDIR)/%.o: $(STDAFXDIR)/stdafx.h.gch %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $(word 2, $^)

$(OBJDIRD)/%.o: $(STDAFXDIR)/stdafx.h.gchd %.cpp %.h
$(CXX) $(CXXFLAGSD) -c -o $@ $(word 2, $^)
36 changes: 36 additions & 0 deletions include/Singleton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <map>
#include <memory>
#include <string>

template <typename T>
class Singleton
{
public:
typedef T derived_type;

template<typename... Args>
static inline void initialize(Args& ... args)
{
derived_type* p(new derived_type(args...));
instance.reset(p);
atomic_rtlogger.store(p, std::memory_order_seq_cst);
}
static inline void destroy() { instance.reset(); }
static inline T& get() { return *instance; }

protected:
Singleton() {};
~Singleton() {};

private:
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);

static std::unique_ptr<T> instance;
static std::atomic<T*> atomic_rtlogger;
};

template<typename T> std::unique_ptr<T> Singleton<T>::instance;
template<typename T> std::atomic<T*> Singleton<T>::atomic_rtlogger;
Loading

0 comments on commit 9490919

Please sign in to comment.