Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try x #1

Merged
merged 5 commits into from Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file removed 3rdParty/gtest-1.6.0__stripped.zip
Binary file not shown.
Binary file added 3rdParty/gtest-1.7.0.zip
Binary file not shown.
44 changes: 15 additions & 29 deletions CMakeLists.txt
Expand Up @@ -31,7 +31,7 @@
#
# In your (windows) Release or (Linux) build directory you should
# now find any of
# "unit_test_lockfree_{hazard|sequential|aquire-release}.exe"
# "unit_test_lockfree_{aquire-release}.exe"
# ====================================================================


Expand All @@ -46,7 +46,7 @@ PROJECT (CIRCULARFIFO)

IF(UNIX)
MESSAGE("-- cmake for *NIX ")
SET(CMAKE_CXX_FLAGS "-Wall -rdynamic -Wunused -std=c++11 ${CMAKE_CXX_FLAGS_DEBUG} -pthread -D_GLIBCXX_USE_NANOSLEEP")
SET(CMAKE_CXX_FLAGS "-Wall -Wunused -std=c++11 -Wall -fPIC -Ofast -m64 -D_GLIBCXX_USE_NANOSLEEP")
ENDIF(UNIX)

IF(MSVC)
Expand All @@ -69,32 +69,29 @@ INCLUDE_DIRECTORIES(${CodeRoot}/g2utilities)


# Google gtest used for unit testing
MESSAGE("Unless already done: Please unzip 3rdParty/gtest-1.6.0__stripped.zip to the folder 3rdParty/gtest-1.6.0__stripped")
SET(RootGTest 3rdParty/gtest-1.6.0__stripped)
MESSAGE("Unless already done: Please unzip 3rdParty/gtest-1.7.0)zip to the folder 3rdParty/gtest-1.7.0)")
SET(RootGTest 3rdParty/gtest-1.7.0)
SET(GTestInclude ${RootGTest}/include
${RootGTest}
${RootGTest}/src)
INCLUDE_DIRECTORIES(${GTestInclude})
SET(SrcGTest
${RootGTest}/src/gtest-all.cc
${RootGTest}/src/gtest_main.cc)
ADD_LiBRARY(gtest_160_lib ${SrcGTest})
ADD_LiBRARY(gtest_lib ${SrcGTest})
ENABLE_TESTING(true)


# Circular FIFO library
SET (SrcFiles
${CodeSrcDir}/circularfifo_hazard_platform_dependent.hpp
#${CodeSrcDir}/circularfifo_memory_sequential_consistent.hpp
#${CodeSrcDir}/circularfifo_memory_relaxed_aquire_release.hpp
${CodeRoot}/g2utilities/g2random.h
${CodeRoot}/g2utilities/g2chrono.h
${CodeRoot}/g2utilities/g2chrono.cpp)
ADD_LiBRARY(CircularFifoCompareLibrary ${SrcFiles})
SET_TARGET_PROPERTIES(CircularFifoCompareLibrary PROPERTIES LINKER_LANGUAGE CXX)
TARGET_LINK_LIBRARIES(CircularFifoCompareLibrary)

SET(CodeLibraries CircularFifoCompareLibrary gtest_160_lib)
SET(CodeLibraries CircularFifoCompareLibrary gtest_lib)


# The actual executable compare *tests*
Expand All @@ -104,12 +101,11 @@ SET (TestSrcFiles
${TestSrcDir}/test_main.cpp)


# Unit-test for the safe, but no-finesse, sequential consistent
# (default) CircularFifo
ADD_EXECUTABLE(unit_test_lockfree_sequential ${TestSrcFiles})
SET_TARGET_PROPERTIES(unit_test_lockfree_sequential PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
SET_TARGET_PROPERTIES(unit_test_lockfree_sequential PROPERTIES COMPILE_DEFINITIONS "MEMORY___SEQUENTIAL_CONSISTENT=1")
TARGET_LINK_LIBRARIES(unit_test_lockfree_sequential ${CodeLibraries})
ADD_EXECUTABLE(unit_test_lockfree_aquire_release_padded ${TestSrcFiles})
SET_TARGET_PROPERTIES(unit_test_lockfree_aquire_release_padded PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
SET_TARGET_PROPERTIES(unit_test_lockfree_aquire_release_padded PROPERTIES COMPILE_DEFINITIONS "MEMORY___RELAXED_AQUIRE_RELEASE_PADDED=1")
TARGET_LINK_LIBRARIES(unit_test_lockfree_aquire_release_padded ${CodeLibraries})



Expand All @@ -120,21 +116,11 @@ SET_TARGET_PROPERTIES(unit_test_lockfree_aquire_release PROPERTIES COMPILE_DEFIN
TARGET_LINK_LIBRARIES(unit_test_lockfree_aquire_release ${CodeLibraries})



# unit-test for the could-be-working, i.e. unsafe since it is outside the C++ standard
# and relies on hack that are HIGHLY platform dependent. This is old school and should be
# avoided
#
# How to break it:
# At least on Linux, gcc on 'non-release' builds this unsafe type breaks easily
# in the unit test.
ADD_EXECUTABLE(unit_test_lockfree_legacy_hazard ${TestSrcFiles})
SET_TARGET_PROPERTIES(unit_test_lockfree_legacy_hazard PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
SET_TARGET_PROPERTIES(unit_test_lockfree_legacy_hazard PROPERTIES COMPILE_DEFINITIONS "HAZARD=1")
TARGET_LINK_LIBRARIES(unit_test_lockfree_legacy_hazard ${CodeLibraries})



# unit-test for the safe, and mutex protected shared_queue
ADD_EXECUTABLE(unit_test_lock_shared ${TestSrcFiles})
SET_TARGET_PROPERTIES(unit_test_lock_shared PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
SET_TARGET_PROPERTIES(unit_test_lock_shared PROPERTIES COMPILE_DEFINITIONS "MEMORY___LOCKED=1")
TARGET_LINK_LIBRARIES(unit_test_lock_shared ${CodeLibraries})



Expand Down
10 changes: 5 additions & 5 deletions g2utilities/g2chrono.cpp
Expand Up @@ -9,17 +9,17 @@

namespace g2
{
typedef std::chrono::high_resolution_clock clock;
typedef std::chrono::microseconds microseconds;
typedef std::chrono::milliseconds milliseconds;
using clock = std::chrono::high_resolution_clock;
using microseconds = std::chrono::duration<float, std::chrono::microseconds::period>;
using milliseconds = std::chrono::duration<float, std::chrono::milliseconds::period>;

clock::time_point now(){return clock::now();}

microseconds intervalUs(const clock::time_point& t1, const clock::time_point& t0)
{return std::chrono::duration_cast<microseconds>(t1 - t0);}
{return microseconds(t1 - t0);}

milliseconds intervalMs(const clock::time_point& t1,const clock::time_point& t0)
{return std::chrono::duration_cast<milliseconds>(t1 - t0);}
{return milliseconds(t1 - t0);}


template<typename Duration>
Expand Down
4 changes: 2 additions & 2 deletions g2utilities/g2random.h
Expand Up @@ -15,7 +15,7 @@ typedef unsigned int Number;
// Random numbers are chosen within the range limits of 'low' and 'high'
// A random number can be retrieved like this:
// Number random_nbr = RandomNumber(0, 99);
auto RandomNumber = [&](const Number& low, const Number& high) -> Number {
auto RandomNumber = [](const Number& low, const Number& high) -> Number {
std::uniform_int_distribution<int> distribution(low, high);
std::mt19937 engine((unsigned int)time(0)); // Mersenne twister MT19937
auto generator = std::bind(distribution, engine); // old-school using bind
Expand All @@ -28,7 +28,7 @@ auto RandomNumber = [&](const Number& low, const Number& high) -> Number {
// does not need to be re-created for each new random number retrieved.
// auto generator = RandomGenerator(0, 99);
// Number random_nbr = generator(); // a random number createds
auto RandomGenerator = [&](const Number& low, const Number& high) -> std::function<Number()> {
auto RandomGenerator = [](const Number& low, const Number& high) -> std::function<Number()> {
std::uniform_int_distribution<int> distribution(low, high);
std::mt19937 engine((unsigned int)time(0)); // Mersenne twister MT19937
auto generator = std::bind(distribution, engine);
Expand Down
40 changes: 0 additions & 40 deletions g2utilities/g2random.h.orig

This file was deleted.

144 changes: 0 additions & 144 deletions src/circularfifo_hazard_platform_dependent.hpp

This file was deleted.

9 changes: 6 additions & 3 deletions src/circularfifo_memory_relaxed_aquire_release.hpp
Expand Up @@ -15,8 +15,7 @@
// it is a "controversy" whether what is tail and what is head
// http://en.wikipedia.org/wiki/FIFO#Head_or_tail_first

#ifndef CIRCULARFIFO_AQUIRE_RELEASE_H_
#define CIRCULARFIFO_AQUIRE_RELEASE_H_
#pragma once

#include <atomic>
#include <cstddef>
Expand Down Expand Up @@ -44,6 +43,10 @@ class CircularFifo{
std::atomic<size_t> _head; // head(output) index
};





template<typename Element, size_t Size>
bool CircularFifo<Element, Size>::push(const Element& item)
{
Expand Down Expand Up @@ -105,4 +108,4 @@ size_t CircularFifo<Element, Size>::increment(size_t idx) const
}

} // memory_relaxed_aquire_release
#endif /* CIRCULARFIFO_AQUIRE_RELEASE_H_ */