Skip to content

Commit

Permalink
Added inline where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Dec 31, 2016
1 parent d54d7ce commit 76a5ff5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 64 deletions.
6 changes: 3 additions & 3 deletions include/ecst/context/entity/constants/invalid_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#pragma once

#include <limits>
#include <ecst/config.hpp>
#include <ecst/aliases.hpp>
#include <ecst/config.hpp>
#include <ecst/context/types.hpp>
#include <limits>

ECST_CONTEXT_ENTITY_NAMESPACE
{
Expand All @@ -20,7 +20,7 @@ ECST_CONTEXT_ENTITY_NAMESPACE
}

/// @brief Returns `true` if `eid` is a valid entity ID.
auto ECST_CONST_FN is_valid_id(entity_id eid) noexcept
inline auto ECST_CONST_FN is_valid_id(entity_id eid) noexcept
{
return eid != impl::invalid_id;
}
Expand Down
9 changes: 5 additions & 4 deletions include/ecst/context/entity/handle/handle.inl
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@

#pragma once

#include "./handle.hpp"
#include "../constants.hpp"
#include "./handle.hpp"

ECST_CONTEXT_ENTITY_NAMESPACE
{
namespace impl
{
handle::handle() noexcept : _id{invalid_id}
inline handle::handle() noexcept : _id{invalid_id}
{
}

handle::handle(uninitialized_handle_init) noexcept
inline handle::handle(uninitialized_handle_init) noexcept
{
}

handle::handle(entity_id id, counter ctr) noexcept : _id{id}, _ctr{ctr}
inline handle::handle(entity_id id, counter ctr) noexcept
: _id{id}, _ctr{ctr}
{
}
}
Expand Down
44 changes: 20 additions & 24 deletions include/ecst/debug/log/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#pragma once

#include <vrm/core/make_array.hpp>
#include <ecst/config.hpp>
#include <ecst/aliases.hpp>
#include "./elog.hpp"
#include <ecst/aliases.hpp>
#include <ecst/config.hpp>
#include <vrm/core/make_array.hpp>

#if defined(ECST_LOG_ENABLED)
#include <iostream>
Expand All @@ -18,13 +18,13 @@ ECST_DEBUG_NAMESPACE
{
namespace impl
{
auto& ECST_CONST_FN last_log() noexcept
inline auto& ECST_CONST_FN last_log() noexcept
{
static int res = -1;
return res;
}

const auto& ECST_CONST_FN tstrings() noexcept
inline const auto& ECST_CONST_FN tstrings() noexcept
{
static auto res = vrmc::make_array( // .
/* 00 */ " ENTITY", // .
Expand Down Expand Up @@ -53,14 +53,14 @@ ECST_DEBUG_NAMESPACE
{
};

auto& ECST_CONST_FN fake_cout() noexcept
inline auto& ECST_CONST_FN fake_cout() noexcept
{
static fake_cout_obj res;
return res;
}

template <typename T>
auto& operator<<(fake_cout_obj& o, T&&) noexcept
inline auto& operator<<(fake_cout_obj& o, T&&) noexcept
{
return o;
}
Expand All @@ -78,32 +78,28 @@ ECST_DEBUG_NAMESPACE
/* 10 */ constexpr auto metadata_bitset = off<10>;

template <typename TType>
auto& log(TType) noexcept
inline auto& log(TType) noexcept
{
return static_if(bool_v<(TType::value >= 0)>)
.then([]() -> auto&
{
.then([]() -> auto& {
#if defined(ECST_LOG_ENABLED)

constexpr auto logt = TType::value;
constexpr auto logt = TType::value;

if(last_log() != logt)
{
std::cout << "\n";
}
if(last_log() != logt)
{
std::cout << "\n";
}

last_log() = logt;
last_log() = logt;

return std::cout << "[" << tstrings()[TType::value]
<< "]\t";
return std::cout << "[" << tstrings()[TType::value]
<< "]\t";
#else
return fake_cout();
return fake_cout();
#endif
})
.else_([]() -> auto&
{
return fake_cout();
})();
})
.else_([]() -> auto& { return fake_cout(); })();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions include/ecst/utils/cv_operations/counter_blocker.inl
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@

#pragma once

#include "./cv_operations.hpp"
#include "./counter_blocker.hpp"
#include "./cv_operations.hpp"

ECST_NAMESPACE
{
counter_blocker::counter_blocker(
inline counter_blocker::counter_blocker(
impl::counter_inner_type initial_count) noexcept
: _counter{initial_count}
{
}

void counter_blocker::decrement_and_notify_one() noexcept
inline void counter_blocker::decrement_and_notify_one() noexcept
{
impl::decrement_cv_counter_and_notify_one(_mutex, _cv, _counter);
}

void counter_blocker::decrement_and_notify_all() noexcept
inline void counter_blocker::decrement_and_notify_all() noexcept
{
impl::decrement_cv_counter_and_notify_all(_mutex, _cv, _counter);
}

template <typename TF>
void counter_blocker::execute_and_wait_until_zero(TF && f) noexcept(
inline void counter_blocker::execute_and_wait_until_zero(TF && f) noexcept(
noexcept(f()))
{
impl::execute_and_wait_until_counter_zero(
Expand Down
46 changes: 18 additions & 28 deletions include/ecst/utils/cv_operations/cv_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#pragma once

#include <utility>
#include <ecst/config.hpp>
#include <ecst/aliases.hpp>
#include <ecst/config.hpp>
#include <utility>

ECST_NAMESPACE
{
Expand All @@ -27,7 +27,7 @@ ECST_NAMESPACE
/// @brief Accesses `cv` and `c` through a `lock_guard` on `mutex`, and
/// calls `f(cv, c)`.
template <typename TF>
void access_cv_counter(
inline void access_cv_counter(
mutex_type& mutex, cv_type& cv, counter_type& c, TF&& f) noexcept
{
lock_guard_type l(mutex);
Expand All @@ -39,42 +39,37 @@ ECST_NAMESPACE

/// @brief Decrements `c` through `mutex`, and calls `f(cv)`.
template <typename TF>
void decrement_cv_counter_then(
inline void decrement_cv_counter_then(
mutex_type& mutex, cv_type& cv, counter_type& c, TF&& f) noexcept
{
access_cv_counter(mutex, cv, c, [&f](auto& x_cv, auto& x_c)
{
ECST_ASSERT(x_c > 0);
--x_c;
access_cv_counter(mutex, cv, c, [&f](auto& x_cv, auto& x_c) {
ECST_ASSERT(x_c > 0);
--x_c;

f(x_cv);
});
f(x_cv);
});
}

/// @brief Decrements `c` through `mutex`, and calls `cv.notify_one()`.
void decrement_cv_counter_and_notify_one(
inline void decrement_cv_counter_and_notify_one(
mutex_type& mutex, cv_type& cv, counter_type& c) noexcept
{
decrement_cv_counter_then(mutex, cv, c, [](auto& x_cv)
{
x_cv.notify_one();
});
decrement_cv_counter_then(
mutex, cv, c, [](auto& x_cv) { x_cv.notify_one(); });
}

/// @brief Decrements `c` through `mutex`, and calls `cv.notify_all()`.
void decrement_cv_counter_and_notify_all(
inline void decrement_cv_counter_and_notify_all(
mutex_type& mutex, cv_type& cv, counter_type& c) noexcept
{
decrement_cv_counter_then(mutex, cv, c, [](auto& x_cv)
{
x_cv.notify_all();
});
decrement_cv_counter_then(
mutex, cv, c, [](auto& x_cv) { x_cv.notify_all(); });
}

/// @brief Executes `f`, locks `mutex`, and waits until `predicate`
/// is `true` through `cv`.
template <typename TPredicate, typename TF>
void execute_and_wait_until(mutex_type& mutex, cv_type& cv,
inline void execute_and_wait_until(mutex_type& mutex, cv_type& cv,
TPredicate&& predicate, TF&& f) noexcept
{
f();
Expand All @@ -86,15 +81,10 @@ ECST_NAMESPACE
/// @brief Locks `mutex`, executes `f` and waits until `c` is zero
/// through `cv`.
template <typename TF>
void execute_and_wait_until_counter_zero(
inline void execute_and_wait_until_counter_zero(
mutex_type& mutex, cv_type& cv, counter_type& c, TF&& f) noexcept
{
execute_and_wait_until(mutex, cv,
[&c]
{
return c == 0;
},
FWD(f));
execute_and_wait_until(mutex, cv, [&c] { return c == 0; }, FWD(f));
}
}
}
Expand Down

0 comments on commit 76a5ff5

Please sign in to comment.