Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
62b9e28
Add imp for subsequent refactoring
mutouyun Jan 2, 2025
6831b05
Add `expected`
mutouyun Jan 6, 2025
838f416
Move the export.h file to the imp directory
mutouyun Jan 6, 2025
94cb6e6
Add `nameof` & `scope_exit`
mutouyun Jan 7, 2025
041970a
libimp => libipc
mutouyun Jan 7, 2025
7f79398
Add `codecvt`
mutouyun Jan 7, 2025
d32252b
Add `fmt`
mutouyun Jan 7, 2025
a4b48e9
Added fmt support for `byte`
mutouyun Jan 7, 2025
78b1d04
Add `error`
mutouyun Jan 7, 2025
6ce508b
Add `log`
mutouyun Jan 7, 2025
359e1ae
`IPC_EXPORT` => `LIBIPC_EXPORT`
mutouyun Jan 7, 2025
8b43340
Add `result`
mutouyun Jan 8, 2025
3aba3a5
Add `system`
mutouyun Jan 8, 2025
41352f9
Update platform-specific feature macros to new interfaces in imp
mutouyun Jan 8, 2025
9ac82b6
Start refactoring memory management, adding `memory_resource`
mutouyun Jan 8, 2025
9e9052f
Optimized partial implementation using `fmt`
mutouyun Jan 9, 2025
de217b4
Add `allocator` and rewrite `allocator_wrapper`
mutouyun Jan 9, 2025
664a349
Add `intrusive_stack`
mutouyun Jan 9, 2025
af6984e
Optimize `memory_resource` & add `monotonic_buffer_resource`
mutouyun Jan 10, 2025
c5a7a5d
Fix fmt function to handle empty strings and update make_prefix templ…
mutouyun Jan 11, 2025
1a14e2a
Update c-cpp.yml
mutouyun Jan 11, 2025
e006ba3
Fix fmt function to handle null pointers and return empty string
mutouyun Jan 11, 2025
81c7c42
Simplify verify_args function to fix error C3249
mutouyun Jan 11, 2025
279c5f1
Adjust the allocator name
mutouyun Jan 15, 2025
aaecfcf
Add `block_pool`
mutouyun Jan 21, 2025
ea041c7
Add `$new`
mutouyun Jan 24, 2025
03a9bba
libipc/memory/resource.h => libipc/mem/resource.h
mutouyun Jan 26, 2025
af2c489
The memory allocator supports runtime dynamic size memory allocation
mutouyun Jan 26, 2025
7fd4041
Simplify the implementation of memory allocation management
mutouyun Jan 27, 2025
ac9a240
Use `$new` instead of `alloc`
mutouyun Feb 4, 2025
fdb8cac
Reimplement the allocator required for the container type with `$new`
mutouyun Feb 13, 2025
8af5a61
Refactoring the generic memory allocator
mutouyun Mar 9, 2025
c28b4a5
Fix the issue caused by inconsistent lifecycle of the global IPC object.
mutouyun May 6, 2025
29d2560
Replace custom hash struct with std::hash in unordered_map definition
mutouyun May 24, 2025
4338557
fix(container_allocator): Fix MSVC compilation by correcting allocato…
mutouyun Dec 1, 2025
11973b9
refactor(uninitialized): Improve construct() overload resolution
mutouyun Dec 1, 2025
a83ba83
fix(test): Fix buffer overflow in data_set caused by array placement new
mutouyun Dec 3, 2025
43b20b2
fix(msvc): Fix C4138 warning by adding space before commented paramet…
mutouyun Dec 3, 2025
c44e9fa
fix(test): Update test.h include paths after master rebase
mutouyun Dec 3, 2025
636d84b
fix(shm_win): Use mem::$delete instead of mem::free in release()
mutouyun Dec 3, 2025
32244ac
fix(platform): Add FreeBSD detection and include detect_plat.h in det…
Dec 9, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: C/C++ CI

on:
push:
branches: [ master, develop, issue-* ]
branches: [ master, develop, issue-*, feature/* ]
pull_request:
branches: [ master, develop ]

Expand Down
8 changes: 4 additions & 4 deletions include/libipc/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <vector>
#include <type_traits>

#include "libipc/export.h"
#include "libipc/imp/export.h"
#include "libipc/def.h"

namespace ipc {

class IPC_EXPORT buffer {
class LIBIPC_EXPORT buffer {
public:
using destructor_t = void (*)(void*, std::size_t);

Expand Down Expand Up @@ -59,8 +59,8 @@ class IPC_EXPORT buffer {
};
}

friend IPC_EXPORT bool operator==(buffer const & b1, buffer const & b2);
friend IPC_EXPORT bool operator!=(buffer const & b1, buffer const & b2);
friend LIBIPC_EXPORT bool operator==(buffer const & b1, buffer const & b2);
friend LIBIPC_EXPORT bool operator!=(buffer const & b1, buffer const & b2);

private:
class buffer_;
Expand Down
66 changes: 66 additions & 0 deletions include/libipc/concur/intrusive_stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* \file libconcur/intrusive_stack.h
* \author mutouyun (orz@orzz.org)
* \brief Define concurrent intrusive stack.
*/
#pragma once

#include <atomic>

namespace ipc {
namespace concur {

/// \brief Intrusive stack node.
/// \tparam T The type of the value.
template <typename T>
struct intrusive_node {
T value;
std::atomic<intrusive_node *> next;
};

/// \brief Intrusive stack.
/// \tparam T The type of the value.
/// \tparam Node The type of the node.
template <typename T, typename Node = intrusive_node<T>>
class intrusive_stack {
public:
using node = Node;

private:
std::atomic<node *> top_{nullptr};

public:
intrusive_stack(intrusive_stack const &) = delete;
intrusive_stack(intrusive_stack &&) = delete;
intrusive_stack &operator=(intrusive_stack const &) = delete;
intrusive_stack &operator=(intrusive_stack &&) = delete;

constexpr intrusive_stack() noexcept = default;

bool empty() const noexcept {
return top_.load(std::memory_order_acquire) == nullptr;
}

void push(node *n) noexcept {
node *old_top = top_.load(std::memory_order_acquire);
do {
n->next.store(old_top, std::memory_order_relaxed);
} while (!top_.compare_exchange_weak(old_top, n, std::memory_order_release
, std::memory_order_acquire));
}

node *pop() noexcept {
node *old_top = top_.load(std::memory_order_acquire);
do {
if (old_top == nullptr) {
return nullptr;
}
} while (!top_.compare_exchange_weak(old_top, old_top->next.load(std::memory_order_relaxed)
, std::memory_order_release
, std::memory_order_acquire));
return old_top;
}
};

} // namespace concur
} // namespace ipc
4 changes: 2 additions & 2 deletions include/libipc/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include <cstdint> // std::uint64_t

#include "libipc/export.h"
#include "libipc/imp/export.h"
#include "libipc/def.h"
#include "libipc/mutex.h"

namespace ipc {
namespace sync {

class IPC_EXPORT condition {
class LIBIPC_EXPORT condition {
condition(condition const &) = delete;
condition &operator=(condition const &) = delete;

Expand Down
29 changes: 15 additions & 14 deletions include/libipc/def.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ using uint_t = typename uint<N>::type;
// constants

enum : std::uint32_t {
invalid_value = (std::numeric_limits<std::uint32_t>::max)(),
default_timeout = 100, // ms
invalid_value = (std::numeric_limits<std::uint32_t>::max)(),
default_timeout = 100, // ms
};

enum : std::size_t {
data_length = 64,
large_msg_limit = data_length,
large_msg_align = 1024,
large_msg_cache = 32,
central_cache_default_size = 1024 * 1024, ///< 1MB
data_length = 64,
large_msg_limit = data_length,
large_msg_align = 1024,
large_msg_cache = 32,
};

enum class relat { // multiplicity of the relationship
single,
multi
single,
multi
};

enum class trans { // transmission
unicast,
broadcast
unicast,
broadcast
};

// producer-consumer policy flag
Expand All @@ -57,17 +58,17 @@ struct relat_trait;

template <relat Rp, relat Rc, trans Ts>
struct relat_trait<wr<Rp, Rc, Ts>> {
constexpr static bool is_multi_producer = (Rp == relat::multi);
constexpr static bool is_multi_consumer = (Rc == relat::multi);
constexpr static bool is_broadcast = (Ts == trans::broadcast);
constexpr static bool is_multi_producer = (Rp == relat::multi);
constexpr static bool is_multi_consumer = (Rc == relat::multi);
constexpr static bool is_broadcast = (Ts == trans::broadcast);
};

template <template <typename> class Policy, typename Flag>
struct relat_trait<Policy<Flag>> : relat_trait<Flag> {};

// the prefix tag of a channel
struct prefix {
char const *str;
char const *str;
};

} // namespace ipc
54 changes: 0 additions & 54 deletions include/libipc/export.h

This file was deleted.

74 changes: 74 additions & 0 deletions include/libipc/imp/aligned.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* \file libipc/aligned.h
* \author mutouyun (orz@orzz.org)
* \brief Defines the type suitable for use as uninitialized storage for types of given type.
*/
#pragma once

#include <array>
#include <cstddef>

#include "libipc/imp/byte.h"

namespace ipc {

/**
* \brief The type suitable for use as uninitialized storage for types of given type.
* std::aligned_storage is deprecated in C++23, so we define our own.
* \tparam T The type to be aligned.
* \tparam AlignT The alignment of the type.
* \see https://en.cppreference.com/w/cpp/types/aligned_storage
* https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1413r3.pdf
*/
template <typename T, std::size_t AlignT = alignof(T)>
class aligned {
alignas(AlignT) std::array<ipc::byte, sizeof(T)> storage_;

public:
/**
* \brief Returns a pointer to the aligned storage.
* \return A pointer to the aligned storage.
*/
T *ptr() noexcept {
return reinterpret_cast<T *>(storage_.data());
}

/**
* \brief Returns a pointer to the aligned storage.
* \return A pointer to the aligned storage.
*/
T const *ptr() const noexcept {
return reinterpret_cast<const T *>(storage_.data());
}

/**
* \brief Returns a reference to the aligned storage.
* \return A reference to the aligned storage.
*/
T &ref() noexcept {
return *ptr();
}

/**
* \brief Returns a reference to the aligned storage.
* \return A reference to the aligned storage.
*/
T const &ref() const noexcept {
return *ptr();
}
};

/**
* \brief Rounds up the given value to the given alignment.
* \tparam T The type of the value.
* \param value The value to be rounded up.
* \param alignment The alignment to be rounded up to.
* \return The rounded up value.
* \see https://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number
*/
template <typename T>
constexpr T round_up(T value, T alignment) noexcept {
return (value + alignment - 1) & ~(alignment - 1);
}

} // namespace ipc
Loading