Skip to content

Create IPC abstractions IpcMessage and IpcChat and use them in the Profiler #8703

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions builds/posix/make.android.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ LIB_PLATFORM_RPATH=-Wl,-rpath,\$$ORIGIN
LibraryFullName=$(LibraryBaseName)
LibrarySoName=$(LibraryBaseName)

# Global c++ flags: firebird needs no RTTI, choose build standard and c++ specific warnings level
PLUSPLUS_FLAGS:= -fno-rtti -std=c++20 -Werror=delete-incomplete -Werror=return-type

COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DARM64 -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath -I$(ROOT)/extern/libtomcrypt/src/headers \
$(CROSS_FLAGS) -fsigned-char \
Expand Down
3 changes: 3 additions & 0 deletions builds/posix/make.android.arme
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ LIB_PLATFORM_RPATH=-Wl,-rpath,\$$ORIGIN
LibraryFullName=$(LibraryBaseName)
LibrarySoName=$(LibraryBaseName)

# Global c++ flags: firebird needs no RTTI, choose build standard and c++ specific warnings level
PLUSPLUS_FLAGS:= -fno-rtti -std=c++20 -Werror=delete-incomplete -Werror=return-type

COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DARM -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath -I$(ROOT)/extern/libtomcrypt/src/headers \
$(CROSS_FLAGS) -fsigned-char \
Expand Down
3 changes: 3 additions & 0 deletions builds/posix/make.android.x86
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ LIB_PLATFORM_RPATH=-Wl,-rpath,\$$ORIGIN
LibraryFullName=$(LibraryBaseName)
LibrarySoName=$(LibraryBaseName)

# Global c++ flags: firebird needs no RTTI, choose build standard and c++ specific warnings level
PLUSPLUS_FLAGS:= -fno-rtti -std=c++20 -Werror=delete-incomplete -Werror=return-type

COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath -I$(ROOT)/extern/libtomcrypt/src/headers \
$(CROSS_FLAGS) \
Expand Down
3 changes: 3 additions & 0 deletions builds/posix/make.android.x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ LIB_PLATFORM_RPATH=-Wl,-rpath,\$$ORIGIN
LibraryFullName=$(LibraryBaseName)
LibrarySoName=$(LibraryBaseName)

# Global c++ flags: firebird needs no RTTI, choose build standard and c++ specific warnings level
PLUSPLUS_FLAGS:= -fno-rtti -std=c++20 -Werror=delete-incomplete -Werror=return-type

COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DAMD64 -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath -I$(ROOT)/extern/libtomcrypt/src/headers \
$(CROSS_FLAGS) \
Expand Down
3 changes: 2 additions & 1 deletion builds/posix/make.shared.variables
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ AllObjects += $(Common_Objects)
# Common test files
COT1:= $(call dirObjects,common/tests)
COT2:= $(call dirObjects,common/classes/tests)
Common_Test_Objects:= $(COT1) $(COT2) $(call makeObjects,yvalve,gds.cpp)
COT3:= $(call dirObjects,common/ipc/tests)
Common_Test_Objects:= $(COT1) $(COT2) $(COT3) $(call makeObjects,yvalve,gds.cpp)

AllObjects += $(Common_Test_Objects)

Expand Down
4 changes: 3 additions & 1 deletion builds/win32/msvc15/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
<ClInclude Include="..\..\..\src\common\intlobj_new.h" />
<ClInclude Include="..\..\..\src\common\IntlParametersBlock.h" />
<ClInclude Include="..\..\..\src\common\IntlUtil.h" />
<ClInclude Include="..\..\..\src\common\ipc\IpcChat.h" />
<ClInclude Include="..\..\..\src\common\ipc\IpcMessage.h" />
<ClInclude Include="..\..\..\src\common\isc_f_proto.h" />
<ClInclude Include="..\..\..\src\common\isc_proto.h" />
<ClInclude Include="..\..\..\src\common\isc_s_proto.h" />
Expand Down Expand Up @@ -423,4 +425,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion builds/win32/msvc15/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,11 @@
<ClInclude Include="..\..\..\src\include\fb_exception.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\common\ipc\IpcChat.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\common\ipc\IpcMessage.h">
<Filter>headers</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
2 changes: 2 additions & 0 deletions builds/win32/msvc15/common_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\common\ipc\tests\IpcChatTest.cpp" />
<ClCompile Include="..\..\..\src\common\ipc\tests\IpcMessageTest.cpp" />
<ClCompile Include="..\..\..\src\common\tests\CommonTest.cpp" />
<ClCompile Include="..\..\..\src\common\tests\CvtTest.cpp" />
<ClCompile Include="..\..\..\src\common\tests\StringTest.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions builds/win32/msvc15/common_test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@
<ClCompile Include="..\..\..\src\yvalve\gds.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\ipc\tests\IpcChatTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\ipc\tests\IpcMessageTest.cpp">
<Filter>source</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ dnl Checks for pthread functions
AC_CHECK_FUNCS(pthread_mutexattr_setprotocol)
AC_CHECK_FUNCS(pthread_mutexattr_setrobust)
AC_CHECK_FUNCS(pthread_mutex_consistent)
AC_CHECK_FUNCS(pthread_mutex_timedlock)
AC_CHECK_FUNCS(pthread_rwlockattr_setkind)
AC_CHECK_FUNCS(pthread_cancel)
AC_CHECK_FUNCS(pthread_atfork)
Expand Down
119 changes: 119 additions & 0 deletions src/common/StdHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
#ifndef FB_COMMON_STD_HELPER_H
#define FB_COMMON_STD_HELPER_H

#include <algorithm>
#include <span>
#include <type_traits>
#include <utility>
#include <variant>
#include <cstddef>
#include "boost/type_traits/copy_cv.hpp"

namespace Firebird {


// To be used with std::visit

template <typename... Ts>
Expand All @@ -37,6 +46,116 @@ struct StdVisitOverloads : Ts...
template <typename... Ts>
StdVisitOverloads(Ts...) -> StdVisitOverloads<Ts...>;


// Variant helpers

template <typename T>
struct IsVariant : std::false_type {};

template <typename... Ts>
struct IsVariant<std::variant<Ts...>> : std::true_type {};

template <typename... Ts>
struct IsVariant<const std::variant<Ts...>> : std::true_type {};

template <typename T>
concept Variant = IsVariant<T>::value;

template <typename T, typename Variant>
struct VariantIndex;

template <typename T, typename... Types>
struct VariantIndex<T, std::variant<Types...>>
{
static constexpr std::size_t value = []() constexpr
{
std::size_t index = 0;
const bool found = ((std::is_same_v<T, Types> ? true : (++index, false)) || ...);
return found ? index : std::variant_npos;
}();
};

template <typename T, typename... Types>
struct VariantIndex<T, const std::variant<Types...>>
{
static constexpr std::size_t value = VariantIndex<T, std::variant<Types...>>::value;
};

template <typename T, Variant V>
constexpr std::size_t VariantIndexValue = VariantIndex<T, V>::value;

template <typename T, typename V>
concept VariantContains = Variant<V> && requires
{
requires VariantIndexValue<T, V> != std::variant_npos;
};

template <typename T, Variant V>
requires VariantContains<T, V>
constexpr std::size_t getVariantIndex()
{
return VariantIndexValue<T, V>;
}


template <Variant V, std::size_t... Is>
constexpr std::size_t maxVariantSizeImpl(std::index_sequence<Is...>)
{
return std::max({sizeof(std::variant_alternative_t<Is, V>)...});
}

template <Variant V>
constexpr std::size_t maxVariantSize()
{
return maxVariantSizeImpl<V>(std::make_index_sequence<std::variant_size_v<V>>{});
}


template <typename V, std::size_t... Is>
constexpr V createVariantByIndexImpl(std::size_t index, std::index_sequence<Is...>)
{
using FactoryFunc = V(*)(void);
constexpr FactoryFunc factories[] = {
+[] { return V{std::in_place_index<Is>}; }...
};

if (index < sizeof...(Is))
return factories[index]();
else
throw std::out_of_range("Invalid variant index: " + std::to_string(index));
}

template <typename V>
constexpr V createVariantByIndex(std::size_t index)
{
return createVariantByIndexImpl<V>(
index,
std::make_index_sequence<std::variant_size_v<V>>{}
);
}


template <Variant V>
constexpr auto getVariantIndexAndSpan(V& message)
{
return std::visit(
[](auto& arg) -> auto
{
using T = std::decay_t<decltype(arg)>;

return std::pair{
getVariantIndex<T, V>(),
std::span<boost::copy_cv_t<V, uint8_t>>{
reinterpret_cast<std::add_pointer_t<boost::copy_cv_t<V, uint8_t>>>(&arg),
sizeof(T)
}
};
},
message
);
}


} // namespace Firebird

#endif // FB_COMMON_STD_HELPER_H
1 change: 1 addition & 0 deletions src/common/file_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static inline constexpr const char* TPC_HDR_FILE = "fb_tpc_%s";
static inline constexpr const char* TPC_BLOCK_FILE = "fb_tpc_%s_%" UQUADFORMAT;
static inline constexpr const char* SNAPSHOTS_FILE = "fb_snap_%s";
static inline constexpr const char* PROFILER_FILE = "fb_profiler_%s_%" UQUADFORMAT;
static inline constexpr const char* IPC_CHAT_CLIENT_FILE = "fb_ipc_chat_%" UQUADFORMAT "_%" UQUADFORMAT;

// Global usage
static inline constexpr const char* TRACE_FILE = "fb" COMMON_FILE_PREFIX "_trace";
Expand Down
Loading
Loading