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

iox-#831 Replace std::function with cxx::function #1411

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
iox-#831 Replace std::function with cxx::function
Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
  • Loading branch information
mossmaurice committed Jun 14, 2022
commit 33a09b00a5de56f56a5a40597ab7b5e1c576e1ab
9 changes: 4 additions & 5 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
#ifndef IOX_HOOFS_CXX_GENERIC_RAII_HPP
#define IOX_HOOFS_CXX_GENERIC_RAII_HPP

#include "iceoryx_hoofs/cxx/function.hpp"
#include "iceoryx_hoofs/cxx/function_ref.hpp"

#include <functional>

namespace iox
{
namespace cxx
Expand All @@ -47,13 +46,13 @@ class GenericRAII
public:
/// @brief constructor which creates GenericRAII that calls only the cleanupFunction on destruction
/// @param[in] cleanupFunction callable which will be called in the destructor
explicit GenericRAII(const std::function<void()>& cleanupFunction) noexcept;
explicit GenericRAII(const function<void()>& cleanupFunction) noexcept;

/// @brief constructor which calls initFunction and stores the cleanupFunction which will be
/// called in the destructor
/// @param[in] initFunction callable which will be called in the constructor
/// @param[in] cleanupFunction callable which will be called in the destructor
GenericRAII(const function_ref<void()>& initFunction, const std::function<void()>& cleanupFunction) noexcept;
GenericRAII(const function_ref<void()>& initFunction, const function<void()>& cleanupFunction) noexcept;

/// @brief calls m_cleanupFunction callable if it was set in the constructor
~GenericRAII() noexcept;
Expand All @@ -71,7 +70,7 @@ class GenericRAII
void destroy() noexcept;

private:
std::function<void()> m_cleanupFunction;
function<void()> m_cleanupFunction;
};

} // namespace cxx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "iceoryx_hoofs/log/logger.hpp"
#include "iceoryx_hoofs/log/logging.hpp"
#include "iceoryx_hoofs/log/logmanager.hpp"
#include "iceoryx_hoofs/cxx/function.hpp"

#include <functional>
#include <iostream>

namespace iox
Expand Down Expand Up @@ -116,7 +116,7 @@ enum class ErrorLevel : uint32_t
template <typename Error>
void errorHandler(const Error error, const ErrorLevel level = ErrorLevel::FATAL) noexcept;

using HandlerFunction = std::function<void(const uint32_t, const char*, const ErrorLevel)>;
using HandlerFunction = cxx::function<void(const uint32_t, const char*, const ErrorLevel)>;

/// @brief Converts an error into its index assuming the enum starts with 'NO_ERROR'
/// @tparam[in] Error type which is used to report the error (typically an enum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#ifndef IOX_HOOFS_CONCURRENT_ACTIVE_OBJECT_HPP
#define IOX_HOOFS_CONCURRENT_ACTIVE_OBJECT_HPP

#include <functional>
#include <thread>

#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
#include "iceoryx_hoofs/internal/concurrent/trigger_queue.hpp"
#include "iceoryx_hoofs/cxx/function.hpp"

namespace iox
{
Expand All @@ -32,15 +32,15 @@ class ActiveObject
protected:
ActiveObject() noexcept;
virtual ~ActiveObject() noexcept;
void addTask(const std::function<void()>& f) noexcept;
void addTask(const cxx::function<void()>& f) noexcept;
void mainLoop() noexcept;
void stopRunning() noexcept;

friend class cxx::optional<ActiveObject>;

private:
static constexpr uint32_t taskQueueSize = 128;
using taskQueue_t = concurrent::TriggerQueue<std::function<void()>, taskQueueSize, concurrent::FiFo>;
using taskQueue_t = concurrent::TriggerQueue<cxx::function<void()>, taskQueueSize, concurrent::FiFo>;

taskQueue_t m_tasks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <atomic>
#include <cstdint>
#include <cstring>
#include <functional>

namespace iox
{
Expand Down
1 change: 0 additions & 1 deletion iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <atomic>
#include <chrono>
#include <functional>
#include <string>

namespace iox
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/source/concurrent/active_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ActiveObject::~ActiveObject() noexcept
stopRunning();
}

void ActiveObject::addTask(const std::function<void()>& f) noexcept
void ActiveObject::addTask(const cxx::function<void()>& f) noexcept
{
m_tasks.push(f);
}
Expand Down
9 changes: 4 additions & 5 deletions iceoryx_hoofs/source/cxx/generic_raii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ namespace iox
{
namespace cxx
{
GenericRAII::GenericRAII(const std::function<void()>& cleanupFunction) noexcept
GenericRAII::GenericRAII(const cxx::function<void()>& cleanupFunction) noexcept
: GenericRAII(function_ref<void()>(), cleanupFunction)
{
}

GenericRAII::GenericRAII(const function_ref<void()>& initFunction,
const std::function<void()>& cleanupFunction) noexcept
GenericRAII::GenericRAII(const function_ref<void()>& initFunction, const function<void()>& cleanupFunction) noexcept
: m_cleanupFunction(cleanupFunction)
{
if (initFunction)
Expand All @@ -52,7 +51,7 @@ GenericRAII& GenericRAII::operator=(GenericRAII&& rhs) noexcept
{
destroy();
m_cleanupFunction = rhs.m_cleanupFunction;
rhs.m_cleanupFunction = std::function<void()>();
rhs.m_cleanupFunction = function<void()>();
}
return *this;
}
Expand All @@ -62,7 +61,7 @@ void GenericRAII::destroy() noexcept
if (m_cleanupFunction)
{
m_cleanupFunction();
m_cleanupFunction = std::function<void()>();
m_cleanupFunction = function<void()>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class PoshRuntime

/// @brief sets runtime factory, terminates if given factory is empty
///
/// @param[in] factory std::function to which the runtime factory should be set
/// @param[in] factory function pointer to which the runtime factory should be set
static void setRuntimeFactory(const factory_t& factory) noexcept;

/// @brief creates the runtime or returns the already existing one -> Singleton
Expand Down