From b093b82473282f223660672a6af30415ed27b07b Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 26 Jan 2014 21:23:26 +0200 Subject: [PATCH] gcc support --- Makefile | 30 ++++++++++++++++++++++++++++++ include/stdafx.h | 27 +++++++++++++++++++++++++++ {test => include}/utils.h | 0 {test => src}/test.cpp | 18 +++++++++++++----- test/stdafx.cpp | 8 -------- test/stdafx.h | 16 ---------------- 6 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 Makefile create mode 100644 include/stdafx.h rename {test => include}/utils.h (100%) rename {test => src}/test.cpp (63%) delete mode 100644 test/stdafx.cpp delete mode 100644 test/stdafx.h diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..102afee4 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +CC = g++ +CCFLAGS = -std=c++11 -pthread -Iinclude -O3 -flto + +all: lib testlog + +testlog: test.o lib + $(CC) -o $testlog test.o libc11log.a $(CCFLAGS) + +lib: factory.o formatters.o line_logger.o os.o + ar rvs libc11log.a $^; + + +test.o: src/test.cpp + $(CC) -c -o $@ $^ $(CCFLAGS) + +factory.o: src/factory.cpp + $(CC) -c -o $@ $^ $(CCFLAGS) + +formatters.o: src/formatters.cpp + $(CC) -c -o $@ $^ $(CCFLAGS) + +line_logger.o: src/line_logger.cpp + $(CC) -c -o $@ $^ $(CCFLAGS) + +os.o: src/os.cpp + $(CC) -c -o $@ $^ $(CCFLAGS) + +.PHONY: clean +clean: + rm *.o diff --git a/include/stdafx.h b/include/stdafx.h new file mode 100644 index 00000000..d2042a58 --- /dev/null +++ b/include/stdafx.h @@ -0,0 +1,27 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// +#pragma once + +#ifdef _MSC_VER +#include "targetver.h" +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#endif + +#include +#include +#include +#include +#include + + +#ifndef _MSC_VER +namespace std { +template +std::unique_ptr make_unique( Args&& ...args ) +{ + return std::unique_ptr( new T( std::forward(args)... ) ); +} +} +#endif diff --git a/test/utils.h b/include/utils.h similarity index 100% rename from test/utils.h rename to include/utils.h diff --git a/test/test.cpp b/src/test.cpp similarity index 63% rename from test/test.cpp rename to src/test.cpp index 36b77eb0..e4ef66f3 100644 --- a/test/test.cpp +++ b/src/test.cpp @@ -2,30 +2,38 @@ // #include "stdafx.h" +#include "c11log/logger.h" +#include "c11log/sinks/async_sink.h" +#include "c11log/sinks/file_sinks.h" +#include "c11log/sinks/stdout_sinks.h" + +#include "utils.h" int main(int argc, char* argv[]) { - - + int nthreads = argc > 1 ? atoi(argv[1]) : 1; auto null_sink = std::make_shared(); + auto stdout_sink = std::make_shared(); auto async = std::make_shared(100); auto fsink = std::make_shared("newlog", "txt", 1024*1024*10 , 2); - async->add_sink(fsink); + async->add_sink(null_sink); c11log::logger logger("test"); logger.add_sink(async); + std::atomic counter { 0 }; auto counter_ptr = &counter; - for (int i = 0; i < 4; i++) + std::cout << "Starting " << nthreads << " threads.." << std::endl; + for (int i = 0; i < nthreads; i++) { new std::thread([&logger, counter_ptr]() { while (true) { - logger.info() << "Hello from thread" << std::this_thread::get_id(); + logger.info() << "Hello from thread " << std::this_thread::get_id() << "\tcounter: " << counter_ptr->load(); (*counter_ptr)++; } diff --git a/test/stdafx.cpp b/test/stdafx.cpp deleted file mode 100644 index ab6cf716..00000000 --- a/test/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : source file that includes just the standard includes -// test.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/test/stdafx.h b/test/stdafx.h deleted file mode 100644 index da4e7055..00000000 --- a/test/stdafx.h +++ /dev/null @@ -1,16 +0,0 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#include -#include -#include - -#include "utils.h" -#include "../include/c11log/logger.h" -#include "../include/c11log/sinks/async_sink.h" -#include "../include/c11log/sinks/stdout_sinks.h" -#include "../include/c11log/sinks/file_sinks.h"