Skip to content

Commit

Permalink
Merge branch 'develop' into ref-eventreceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
gtremper committed Aug 1, 2014
2 parents 62a07e3 + aff420f commit e963698
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 36 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ set(autowiring_VERSION_PATCH 0)
# Clang needs special additional flags to build with C++11
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message("Clang C++11")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
if (APPLE)
# Apple needs us to tell it that we're using libc++, or it will try to use libstdc++ instead
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
else()
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message("GCC C++11")
set(CMAKE_CXX_FLAGS "-std=c++11")
Expand Down
17 changes: 9 additions & 8 deletions autowiring/AutoPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,25 @@ class AutoPacket:
/// If multiple values are specified, all will be simultaneously made valid and
/// then invalidated.
/// </remarks>
template<class... Ts>
void DecorateImmediate(const Ts&... immeds) {
template<class T, class... Ts>
void DecorateImmediate(const T& immed, const Ts&... immeds) {
// These are the things we're going to be working with while we perform immediate decoration:
static const std::type_info* sc_typeInfo [] = {&typeid(Ts)...};
const void* pvImmeds[] = {&immeds...};
DecorationDisposition* pTypeSubs[sizeof...(Ts)];
static const std::type_info* sc_typeInfo [] = {&typeid(T), &typeid(Ts)...};
const void* pvImmeds [] = {&immed, &immeds...};
DecorationDisposition* pTypeSubs[1 + sizeof...(Ts)];

// None of the inputs may be shared pointers--if any of the inputs are shared pointers, they must be attached
// to this packet via Decorate, or else dereferenced and used that way.
static_assert(
!is_shared_ptr<T>::value &&
!is_any<is_shared_ptr<Ts>...>::value,
"DecorateImmediate must not be used to attach a shared pointer, use Decorate on such a decoration instead"
);

// Perform standard decoration with a short initialization:
{
std::lock_guard<std::mutex> lk(m_lock);
for(size_t i = 0; i < sizeof...(Ts); i++) {
for(size_t i = 0; i <= sizeof...(Ts); i++) {
pTypeSubs[i] = &m_decorations[*sc_typeInfo[i]];
if(pTypeSubs[i]->wasCheckedOut) {
std::stringstream ss;
Expand All @@ -388,11 +389,11 @@ class AutoPacket:
}

// Now trigger a rescan to hit any deferred, unsatisfiable entries:
static const std::type_info* lamda_typeInfos [] = {&typeid(Ts)...};
static const std::type_info* lamda_typeInfos [] = {&typeid(T), &typeid(Ts)...};
for(auto ti : lamda_typeInfos)
MarkUnsatisfiable(*ti);
}),
PulseSatisfaction(pTypeSubs, sizeof...(Ts));
PulseSatisfaction(pTypeSubs, 1 + sizeof...(Ts));
}

/// <returns>
Expand Down
11 changes: 7 additions & 4 deletions autowiring/ObjectPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,14 @@ class ObjectPool
/// The Finalize function will be applied is in the shared_ptr destructor.
/// </remarks>
std::shared_ptr<T> Wrap(T* pObj) {
// Initialize the issued object
m_initial(*pObj);

// Fill the shared pointer with the object we created, and ensure that we override
// the destructor so that the object is returned to the pool when it falls out of
// scope.
size_t poolVersion = m_poolVersion;
auto monitor = m_monitor;
std::function<void(T&)> final = m_final;

return std::shared_ptr<T>(
auto retVal = std::shared_ptr<T>(
pObj,
[poolVersion, monitor, final](T* ptr) {
// Finalize object before destruction or return to pool
Expand All @@ -147,6 +144,12 @@ class ObjectPool
static_cast<ObjectPool<T>*>(monitor->GetOwner())->Return(poolVersion, unique);
}
);

// Initialize the issued object, now that a shared pointer has been created for it
m_initial(*pObj);

// All done
return retVal;
}

void Return(size_t poolVersion, std::unique_ptr<T>& unique) {
Expand Down
2 changes: 1 addition & 1 deletion autowiring/TeardownNotifier.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "C++11/cpp11.h"
#include "contrib/C++11/cpp11.h"
#include <list>
#include FUNCTIONAL_HEADER

Expand Down
2 changes: 1 addition & 1 deletion autowiring/fast_pointer_cast.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "C++11/cpp11.h"
#include <contrib/C++11/cpp11.h>
#include MEMORY_HEADER
#include TYPE_TRAITS_HEADER

Expand Down
2 changes: 1 addition & 1 deletion autowiring/thread_specific_ptr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "C++11/cpp11.h"
#include "contrib/C++11/cpp11.h"
#include FUNCTIONAL_HEADER

// platform specific headers
Expand Down
34 changes: 17 additions & 17 deletions contrib/C++11/cpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* exception_ptr availability
*********************/
#if (defined(__APPLE__) && !defined(_LIBCPP_VERSION)) || __ANDROID__
#define EXCEPTION_PTR_HEADER <C++11/boost_exception_ptr.h>
#define EXCEPTION_PTR_HEADER <contrib/C++11/boost_exception_ptr.h>
#else
#define EXCEPTION_PTR_HEADER <stdexcept>
#define throw_rethrowable throw
Expand All @@ -82,7 +82,7 @@
#if STL11_ALLOWED
#define SYSTEM_ERROR_HEADER <system_error>
#else
#define SYSTEM_ERROR_HEADER <C++11/boost_system_error.h>
#define SYSTEM_ERROR_HEADER <contrib/C++11/boost_system_error.h>
#endif

/*********************
Expand All @@ -91,7 +91,7 @@
#if _MSC_VER >= 1700 || (STL11_ALLOWED && !__ANDROID__)
#define FUTURE_HEADER <future>
#else
#define FUTURE_HEADER <C++11/boost_future.h>
#define FUTURE_HEADER <contrib/C++11/boost_future.h>
#endif

/**
Expand All @@ -101,7 +101,7 @@
#if STL11_ALLOWED
#define TYPE_INDEX_HEADER <typeindex>
#else
#define TYPE_INDEX_HEADER <C++11/type_index.h>
#define TYPE_INDEX_HEADER <contrib/C++11/type_index.h>
#endif

/*********************
Expand All @@ -122,7 +122,7 @@
#define TYPE_TRAITS_HEADER <type_traits>
#endif
#else
#define TYPE_TRAITS_HEADER <C++11/boost_type_traits.h>
#define TYPE_TRAITS_HEADER <contrib/C++11/boost_type_traits.h>
#endif

/*********************
Expand All @@ -139,9 +139,9 @@
#endif

#if SHARED_PTR_IN_STL && STL11_ALLOWED
#define MEMORY_HEADER <C++11/memory.h>
#define MEMORY_HEADER <contrib/C++11/memory.h>
#else
#define MEMORY_HEADER <C++11/memory_nostl11.h>
#define MEMORY_HEADER <contrib/C++11/memory_nostl11.h>
#endif

/*********************
Expand Down Expand Up @@ -175,7 +175,7 @@
#define FUNCTIONAL_HEADER <functional>
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#else
#define FUNCTIONAL_HEADER <C++11/boost_functional.h>
#define FUNCTIONAL_HEADER <contrib/C++11/boost_functional.h>
#endif

#ifndef LAMBDAS_AVAILABLE
Expand All @@ -196,7 +196,7 @@
#if ARRAYS_AVAILABLE
#define ARRAY_HEADER <array>
#else
#define ARRAY_HEADER <C++11/boost_array.h>
#define ARRAY_HEADER <contrib/C++11/boost_array.h>
#endif

/**
Expand All @@ -217,7 +217,7 @@
#if !defined(__APPLE__) || __cplusplus >= 201103L
#define BOOST_NO_UNICODE_LITERALS 1
#endif
#define RVALUE_HEADER <C++11/boost_rvalue.h>
#define RVALUE_HEADER <contrib/C++11/boost_rvalue.h>
#endif

/**
Expand All @@ -226,7 +226,7 @@
#if STL11_ALLOWED
#define ATOMIC_HEADER <atomic>
#else
#define ATOMIC_HEADER <C++11/boost_atomic.h>
#define ATOMIC_HEADER <contrib/C++11/boost_atomic.h>
#endif

/**
Expand All @@ -235,16 +235,16 @@
#if STL11_ALLOWED
#define STL_TUPLE_HEADER <tuple>
#else
#define STL_TUPLE_HEADER <C++11/boost_tuple.h>
#define STL_TUPLE_HEADER <contrib/C++11/boost_tuple.h>
#endif

/**
* Mutex
*/
#if STL11_ALLOWED && !__ANDROID__
#define MUTEX_HEADER <C++11/mutex.h>
#define MUTEX_HEADER <contrib/C++11/mutex.h>
#else
#define MUTEX_HEADER <C++11/boost_mutex.h>
#define MUTEX_HEADER <contrib/C++11/boost_mutex.h>
#endif

/**
Expand All @@ -254,7 +254,7 @@
#define THREAD_HEADER <thread>
#define _WEBSOCKETPP_CPP11_THREAD_
#else
#define THREAD_HEADER <C++11/boost_thread.h>
#define THREAD_HEADER <contrib/C++11/boost_thread.h>
#endif

/**
Expand All @@ -263,7 +263,7 @@
#if STL11_ALLOWED && !__ANDROID__
#define CHRONO_HEADER <chrono>
#else
#define CHRONO_HEADER <C++11/boost_chrono.h>
#define CHRONO_HEADER <contrib/C++11/boost_chrono.h>
#endif

/**
Expand All @@ -272,7 +272,7 @@
#if STL11_ALLOWED
#define UTILITY_HEADER <utility>
#else
#define UTILITY_HEADER <C++11/boost_utility.h>
#define UTILITY_HEADER <contrib/C++11/boost_utility.h>
#endif

/**
Expand Down
2 changes: 1 addition & 1 deletion contrib/C++11/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#pragma once

#include <memory>
#include "C++11/make_unique.h"
#include "contrib/C++11/make_unique.h"
2 changes: 1 addition & 1 deletion src/autonet/test/AutoNetServerTest.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include <EnclosedContextTestBase.hpp>
#include <gtest/gtest.h>

class AutoNetServerTest:
public testing::Test
Expand Down
2 changes: 1 addition & 1 deletion src/autowiring/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
#endif

// C++11 glue logic, for platforms that have incomplete C++11 support
#include "C++11/cpp11.h"
#include "contrib/C++11/cpp11.h"
26 changes: 26 additions & 0 deletions src/autowiring/test/AutoFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,3 +1073,29 @@ TEST_F(AutoFilterTest, WaitWhilePacketOutstanding) {
packet.reset();
ASSERT_TRUE(ctxt->Wait(std::chrono::milliseconds(1))) << "Wait incorrectly timed out when nothing should have been running";
}

class DecoratesAndAcceptsNothing:
public CoreThread
{
public:
Deferred AutoFilter(Decoration<0>& dec) {
dec.i = 105;
return Deferred(this);
}
};

TEST_F(AutoFilterTest, DeferredDecorateOnly) {
AutoCurrentContext ctxt;
AutoRequired<DecoratesAndAcceptsNothing> daan;
AutoRequired<AutoPacketFactory> factory;

ctxt->Initiate();
auto packet = factory->NewPacket();

ctxt->SignalShutdown();
ASSERT_TRUE(daan->WaitFor(std::chrono::seconds(5)));

const Decoration<0>* dec;
ASSERT_TRUE(packet->Get(dec)) << "Deferred decorator didn't attach a decoration to an issued packet";
ASSERT_EQ(105, dec->i) << "Deferred decorate-only AutoFilter did not properly attach before context termination";
}

0 comments on commit e963698

Please sign in to comment.