aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transports/winsock/winsock.cpp4
-rw-r--r--src/transports/winsock/xmake.lua2
-rw-r--r--src/zen/internalfile.h2
-rw-r--r--src/zenbase/README.md6
-rw-r--r--src/zenbase/include/zenbase/atomic.h (renamed from src/zencore/include/zencore/atomic.h)2
-rw-r--r--src/zenbase/include/zenbase/concepts.h46
-rw-r--r--src/zenbase/include/zenbase/refcount.h (renamed from src/zencore/include/zencore/refcount.h)19
-rw-r--r--src/zenbase/include/zenbase/zenbase.h248
-rw-r--r--src/zenbase/xmake.lua7
-rw-r--r--src/zencore/include/zencore/compactbinarybuilder.h2
-rw-r--r--src/zencore/include/zencore/compactbinaryvalidation.h2
-rw-r--r--src/zencore/include/zencore/guid.h1
-rw-r--r--src/zencore/include/zencore/intmath.h1
-rw-r--r--src/zencore/include/zencore/iobuffer.h2
-rw-r--r--src/zencore/include/zencore/session.h1
-rw-r--r--src/zencore/include/zencore/sharedbuffer.h2
-rw-r--r--src/zencore/include/zencore/stats.h2
-rw-r--r--src/zencore/include/zencore/uid.h2
-rw-r--r--src/zencore/include/zencore/workthreadpool.h2
-rw-r--r--src/zencore/include/zencore/zencore.h336
-rw-r--r--src/zencore/refcount.cpp2
-rw-r--r--src/zencore/xmake.lua1
-rw-r--r--src/zencore/zencore.cpp3
-rw-r--r--src/zenhttp/httpserver.cpp2
-rw-r--r--src/zenhttp/include/zenhttp/httpplugin.h2
-rw-r--r--src/zenhttp/include/zenhttp/httpserver.h2
-rw-r--r--src/zenserver-test/projectclient.h2
-rw-r--r--src/zenserver-test/zenserver-test.cpp2
-rw-r--r--src/zenserver/upstream/jupiter.h2
-rw-r--r--src/zenserver/vfs/vfsservice.h2
-rw-r--r--src/zenserver/zenserver.cpp2
-rw-r--r--src/zenutil/include/zenutil/cache/cachepolicy.h2
-rw-r--r--src/zenutil/include/zenutil/statsreporter.h2
-rw-r--r--src/zenvfs/include/zenvfs/vfs.h2
34 files changed, 374 insertions, 343 deletions
diff --git a/src/transports/winsock/winsock.cpp b/src/transports/winsock/winsock.cpp
index 7b349361e..28ac10ec1 100644
--- a/src/transports/winsock/winsock.cpp
+++ b/src/transports/winsock/winsock.cpp
@@ -9,8 +9,8 @@
#include <optional>
#include <thread>
-#include <zencore/refcount.h>
-#include <zencore/zencore.h>
+#include <zenbase/concepts.h>
+#include <zenbase/refcount.h>
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0A00
diff --git a/src/transports/winsock/xmake.lua b/src/transports/winsock/xmake.lua
index 781ead179..552a62702 100644
--- a/src/transports/winsock/xmake.lua
+++ b/src/transports/winsock/xmake.lua
@@ -6,7 +6,7 @@ target("winsock")
add_headerfiles("**.h")
add_files("**.cpp")
add_links("Ws2_32")
- add_includedirs(".", "../../zencore/include")
+ add_includedirs(".", "../../zenbase/include")
set_symbols("debug")
add_deps("transport-sdk")
diff --git a/src/zen/internalfile.h b/src/zen/internalfile.h
index 22153a460..90d370e28 100644
--- a/src/zen/internalfile.h
+++ b/src/zen/internalfile.h
@@ -4,8 +4,8 @@
#include <zencore/zencore.h>
+#include <zenbase/refcount.h>
#include <zencore/iobuffer.h>
-#include <zencore/refcount.h>
#include <zencore/thread.h>
#if ZEN_PLATFORM_WINDOWS
diff --git a/src/zenbase/README.md b/src/zenbase/README.md
new file mode 100644
index 000000000..cc1affa42
--- /dev/null
+++ b/src/zenbase/README.md
@@ -0,0 +1,6 @@
+This is a header-only library which mostly contains definitions to
+support different platforms and compilers.
+
+It is part of the zen codebase but is intended to be consumable
+separately to zenbase etc to support standalone transport plug-ins
+and similar.
diff --git a/src/zencore/include/zencore/atomic.h b/src/zenbase/include/zenbase/atomic.h
index bf549e21d..4ad7962cf 100644
--- a/src/zencore/include/zencore/atomic.h
+++ b/src/zenbase/include/zenbase/atomic.h
@@ -2,7 +2,7 @@
#pragma once
-#include <zencore/zencore.h>
+#include <zenbase/zenbase.h>
#if ZEN_COMPILER_MSC
# include <intrin.h>
diff --git a/src/zenbase/include/zenbase/concepts.h b/src/zenbase/include/zenbase/concepts.h
new file mode 100644
index 000000000..d4a9d75e8
--- /dev/null
+++ b/src/zenbase/include/zenbase/concepts.h
@@ -0,0 +1,46 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <zenbase/zenbase.h>
+
+// At the time of writing only ver >= 13 of LLVM's libc++ has an implementation
+// of std::integral. Some platforms like Ubuntu and Mac OS are still on 12.
+#if defined(__cpp_lib_concepts)
+# include <concepts>
+template<class T>
+concept Integral = std::integral<T>;
+template<class T>
+concept SignedIntegral = std::signed_integral<T>;
+template<class T>
+concept UnsignedIntegral = std::unsigned_integral<T>;
+template<class F, class... A>
+concept Invocable = std::invocable<F, A...>;
+template<class D, class B>
+concept DerivedFrom = std::derived_from<D, B>;
+#else
+# include <functional> // for std::invoke below
+
+template<class T>
+concept Integral = std::is_integral_v<T>;
+template<class T>
+concept SignedIntegral = Integral<T> && std::is_signed_v<T>;
+template<class T>
+concept UnsignedIntegral = Integral<T> && !std::is_signed_v<T>;
+template<class F, class... A>
+concept Invocable = requires(F&& f, A&&... a)
+{
+ std::invoke(std::forward<F>(f), std::forward<A>(a)...);
+};
+template<class D, class B>
+concept DerivedFrom = std::is_base_of_v<B, D> && std::is_convertible_v<const volatile D*, const volatile B*>;
+#endif
+
+#if defined(__cpp_lib_ranges)
+# include <ranges>
+template<typename T>
+concept ContiguousRange = std::ranges::contiguous_range<T>;
+#else
+template<typename T>
+concept ContiguousRange = true;
+#endif
diff --git a/src/zencore/include/zencore/refcount.h b/src/zenbase/include/zenbase/refcount.h
index 74a8f3ac0..3afcf467c 100644
--- a/src/zencore/include/zencore/refcount.h
+++ b/src/zenbase/include/zenbase/refcount.h
@@ -1,20 +1,15 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
-#include "atomic.h"
-#include "zencore.h"
+#include <zenbase/atomic.h>
+#include <zenbase/concepts.h>
#include <compare>
namespace zen {
/**
- * Helper base class for reference counted objects using intrusive reference counts
- *
- * This class is pretty straightforward but does one thing which may be unexpected:
- *
- * - Instances on the stack are initialized with a reference count of one to ensure
- * nobody tries to accidentally delete it. (TODO: is this really useful?)
+ * Helper base class for reference counted objects using intrusive reference counting
*/
class RefCounted
{
@@ -25,12 +20,12 @@ public:
inline uint32_t AddRef() const { return AtomicIncrement(const_cast<RefCounted*>(this)->m_RefCount); }
inline uint32_t Release() const
{
- uint32_t refCount = AtomicDecrement(const_cast<RefCounted*>(this)->m_RefCount);
- if (refCount == 0)
+ const uint32_t RefCount = AtomicDecrement(const_cast<RefCounted*>(this)->m_RefCount);
+ if (RefCount == 0)
{
delete this;
}
- return refCount;
+ return RefCount;
}
// Copying reference counted objects doesn't make a lot of sense generally, so let's prevent it
@@ -182,6 +177,4 @@ private:
friend class Ref;
};
-void refcount_forcelink();
-
} // namespace zen
diff --git a/src/zenbase/include/zenbase/zenbase.h b/src/zenbase/include/zenbase/zenbase.h
new file mode 100644
index 000000000..1df375b28
--- /dev/null
+++ b/src/zenbase/include/zenbase/zenbase.h
@@ -0,0 +1,248 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <cinttypes>
+#include <version>
+
+#ifdef __clang__
+# include <type_traits>
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+// Platform
+//
+
+#define ZEN_PLATFORM_WINDOWS 0
+#define ZEN_PLATFORM_LINUX 0
+#define ZEN_PLATFORM_MAC 0
+
+#ifdef _WIN32
+# undef ZEN_PLATFORM_WINDOWS
+# define ZEN_PLATFORM_WINDOWS 1
+# define ZEN_PLATFORM_NAME "Windows"
+#elif defined(__linux__)
+# undef ZEN_PLATFORM_LINUX
+# define ZEN_PLATFORM_LINUX 1
+# define ZEN_PLATFORM_NAME "Linux"
+#elif defined(__APPLE__)
+# undef ZEN_PLATFORM_MAC
+# define ZEN_PLATFORM_MAC 1
+# define ZEN_PLATFORM_NAME "MacOS"
+#endif
+
+#if ZEN_PLATFORM_WINDOWS
+# if !defined(NOMINMAX)
+# define NOMINMAX // stops Windows.h from defining 'min/max' macros
+# endif
+# if !defined(NOGDI)
+# define NOGDI
+# endif
+# if !defined(WIN32_LEAN_AND_MEAN)
+# define WIN32_LEAN_AND_MEAN // cut-down what Windows.h defines
+# endif
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+// Compiler
+//
+
+#define ZEN_COMPILER_CLANG 0
+#define ZEN_COMPILER_MSC 0
+#define ZEN_COMPILER_GCC 0
+
+// Clang can define __GNUC__ and/or _MSC_VER so we check for Clang first
+#ifdef __clang__
+# undef ZEN_COMPILER_CLANG
+# define ZEN_COMPILER_CLANG 1
+#elif defined(_MSC_VER)
+# undef ZEN_COMPILER_MSC
+# define ZEN_COMPILER_MSC 1
+#elif defined(__GNUC__)
+# undef ZEN_COMPILER_GCC
+# define ZEN_COMPILER_GCC 1
+#else
+# error Unknown compiler
+#endif
+
+#if ZEN_COMPILER_MSC
+# pragma warning(disable : 4324) // warning C4324: '<type>': structure was padded due to alignment specifier
+# pragma warning(default : 4668) // warning C4668: 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
+# pragma warning(default : 4100) // warning C4100: 'identifier' : unreferenced formal parameter
+# pragma warning( \
+ disable : 4373) // '%$S': virtual function overrides '%$pS', previous versions of the compiler did not override when parameters
+ // only differed by const/volatile qualifiers
+ // https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4373
+#endif
+
+#ifndef ZEN_THIRD_PARTY_INCLUDES_START
+# if ZEN_COMPILER_MSC
+# define ZEN_THIRD_PARTY_INCLUDES_START \
+ __pragma(warning(push)) __pragma(warning(disable : 4668)) /* C4668: use of undefined preprocessor macro */ \
+ __pragma(warning(disable : 4305)) /* C4305: 'if': truncation from 'uint32' to 'bool' */ \
+ __pragma(warning(disable : 4267)) /* C4267: '=': conversion from 'size_t' to 'US' */ \
+ __pragma(warning(disable : 4127)) /* C4127: conditional expression is constant */ \
+ __pragma(warning(disable : 4189)) /* C4189: local variable is initialized but not referenced */ \
+ __pragma(warning(disable : 5105)) /* C5105: macro expansion producing 'defined' has undefined behavior */
+# elif ZEN_COMPILER_CLANG
+# define ZEN_THIRD_PARTY_INCLUDES_START \
+ _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wundef\"") \
+ _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") _Pragma("clang diagnostic ignored \"-Wunused-variable\"")
+# elif ZEN_COMPILER_GCC
+# define ZEN_THIRD_PARTY_INCLUDES_START \
+ _Pragma("GCC diagnostic push") /* NB. ignoring -Wundef doesn't work with GCC */ \
+ _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
+# endif
+#endif
+
+#ifndef ZEN_THIRD_PARTY_INCLUDES_END
+# if ZEN_COMPILER_MSC
+# define ZEN_THIRD_PARTY_INCLUDES_END __pragma(warning(pop))
+# elif ZEN_COMPILER_CLANG
+# define ZEN_THIRD_PARTY_INCLUDES_END _Pragma("clang diagnostic pop")
+# elif ZEN_COMPILER_GCC
+# define ZEN_THIRD_PARTY_INCLUDES_END _Pragma("GCC diagnostic pop")
+# endif
+#endif
+
+#if ZEN_COMPILER_MSC
+# define ZEN_DEBUG_BREAK() \
+ do \
+ { \
+ __debugbreak(); \
+ } while (0)
+#else
+# define ZEN_DEBUG_BREAK() \
+ do \
+ { \
+ __builtin_trap(); \
+ } while (0)
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+// C++20 support
+//
+
+// Clang
+#if ZEN_COMPILER_CLANG && __clang_major__ < 12
+# error clang-12 onwards is required for C++20 support
+#endif
+
+// GCC
+#if ZEN_COMPILER_GCC && __GNUC__ < 11
+# error GCC-11 onwards is required for C++20 support
+#endif
+
+// GNU libstdc++
+#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
+# error GNU libstdc++-11 onwards is required for C++20 support
+#endif
+
+// LLVM libc++
+#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 12000
+# error LLVM libc++-12 onwards is required for C++20 support
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+// Architecture
+//
+
+#if defined(__amd64__) || defined(_M_X64)
+# define ZEN_ARCH_X64 1
+# define ZEN_ARCH_ARM64 0
+#elif defined(__arm64__) || defined(_M_ARM64)
+# define ZEN_ARCH_X64 0
+# define ZEN_ARCH_ARM64 1
+#else
+# error Unknown architecture
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+// Build flavor
+//
+
+#ifdef NDEBUG
+# define ZEN_BUILD_DEBUG 0
+# define ZEN_BUILD_RELEASE 1
+# define ZEN_BUILD_NAME "release"
+#else
+# define ZEN_BUILD_DEBUG 1
+# define ZEN_BUILD_RELEASE 0
+# define ZEN_BUILD_NAME "debug"
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+
+#define ZEN_PLATFORM_SUPPORTS_UNALIGNED_LOADS 1
+
+#if defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 4
+# define ZEN_SIZEOF_WCHAR_T 4
+#else
+static_assert(sizeof(wchar_t) == 2, "wchar_t is expected to be two bytes in size");
+# define ZEN_SIZEOF_WCHAR_T 2
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+
+#ifdef __clang__
+template<typename T>
+auto ZenArrayCountHelper(T& t) -> typename std::enable_if<__is_array(T), char (&)[sizeof(t) / sizeof(t[0]) + 1]>::type;
+#else
+template<typename T, uint32_t N>
+char (&ZenArrayCountHelper(const T (&)[N]))[N + 1];
+#endif
+
+#define ZEN_ARRAY_COUNT(array) (sizeof(ZenArrayCountHelper(array)) - 1)
+
+//////////////////////////////////////////////////////////////////////////
+
+#if ZEN_COMPILER_MSC
+# define ZEN_NOINLINE __declspec(noinline)
+#else
+# define ZEN_NOINLINE __attribute__((noinline))
+#endif
+
+#if ZEN_PLATFORM_WINDOWS
+# define ZEN_EXE_SUFFIX_LITERAL ".exe"
+#else
+# define ZEN_EXE_SUFFIX_LITERAL ""
+#endif
+
+#define ZEN_UNUSED(...) ((void)__VA_ARGS__)
+
+//////////////////////////////////////////////////////////////////////////
+
+#if ZEN_COMPILER_MSC
+# define ZEN_DISABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", off))
+# define ZEN_ENABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", on))
+#elif ZEN_COMPILER_GCC
+# define ZEN_DISABLE_OPTIMIZATION_ACTUAL _Pragma("GCC push_options") _Pragma("GCC optimize (\"O0\")")
+# define ZEN_ENABLE_OPTIMIZATION_ACTUAL _Pragma("GCC pop_options")
+#elif ZEN_COMPILER_CLANG
+# define ZEN_DISABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize off")
+# define ZEN_ENABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize on")
+#endif
+
+// Set up optimization control macros, now that we have both the build settings and the platform macros
+#define ZEN_DISABLE_OPTIMIZATION ZEN_DISABLE_OPTIMIZATION_ACTUAL
+
+#if ZEN_BUILD_DEBUG
+# define ZEN_ENABLE_OPTIMIZATION ZEN_DISABLE_OPTIMIZATION_ACTUAL
+#else
+# define ZEN_ENABLE_OPTIMIZATION ZEN_ENABLE_OPTIMIZATION_ACTUAL
+#endif
+
+#define ZEN_ENABLE_OPTIMIZATION_ALWAYS ZEN_ENABLE_OPTIMIZATION_ACTUAL
+
+#if ZEN_PLATFORM_WINDOWS
+// Tells the compiler to put the decorated function in a certain section (aka. segment) of the executable.
+# define ZEN_CODE_SECTION(Name) __declspec(code_seg(Name))
+# define ZEN_DATA_SECTION(Name) __declspec(allocate(Name))
+# define ZEN_FORCENOINLINE __declspec(noinline) /* Force code to NOT be inline */
+# define LINE_TERMINATOR_ANSI "\r\n"
+#else
+# define ZEN_CODE_SECTION(Name)
+# define ZEN_DATA_SECTION(Name)
+# define ZEN_FORCENOINLINE
+# define LINE_TERMINATOR_ANSI "\n"
+#endif
diff --git a/src/zenbase/xmake.lua b/src/zenbase/xmake.lua
new file mode 100644
index 000000000..5a00a5ddf
--- /dev/null
+++ b/src/zenbase/xmake.lua
@@ -0,0 +1,7 @@
+-- Copyright Epic Games, Inc. All Rights Reserved.
+
+target('zenbase')
+ set_kind("headeronly")
+ set_group("libs")
+ add_headerfiles("**.h")
+ add_includedirs("include", {public=true})
diff --git a/src/zencore/include/zencore/compactbinarybuilder.h b/src/zencore/include/zencore/compactbinarybuilder.h
index e8d981fcb..9cb8f7193 100644
--- a/src/zencore/include/zencore/compactbinarybuilder.h
+++ b/src/zencore/include/zencore/compactbinarybuilder.h
@@ -6,10 +6,10 @@
#include <zencore/compactbinary.h>
+#include <zenbase/refcount.h>
#include <zencore/enumflags.h>
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
-#include <zencore/refcount.h>
#include <zencore/sha1.h>
#include <atomic>
diff --git a/src/zencore/include/zencore/compactbinaryvalidation.h b/src/zencore/include/zencore/compactbinaryvalidation.h
index 4f1bdbb37..b23c6d51d 100644
--- a/src/zencore/include/zencore/compactbinaryvalidation.h
+++ b/src/zencore/include/zencore/compactbinaryvalidation.h
@@ -4,11 +4,11 @@
#include <zencore/zencore.h>
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
#include <zencore/enumflags.h>
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
-#include <zencore/refcount.h>
#include <zencore/sha1.h>
#include <gsl/gsl-lite.hpp>
diff --git a/src/zencore/include/zencore/guid.h b/src/zencore/include/zencore/guid.h
index 13e1b5540..ee38aded0 100644
--- a/src/zencore/include/zencore/guid.h
+++ b/src/zencore/include/zencore/guid.h
@@ -6,6 +6,7 @@
#include <zencore/zencore.h>
#include <compare>
+#include <string_view>
namespace zen {
diff --git a/src/zencore/include/zencore/intmath.h b/src/zencore/include/zencore/intmath.h
index 0d87e1b78..2b59d6f4a 100644
--- a/src/zencore/include/zencore/intmath.h
+++ b/src/zencore/include/zencore/intmath.h
@@ -5,6 +5,7 @@
#include "zencore.h"
#include <stdint.h>
+#include <zenbase/concepts.h>
//////////////////////////////////////////////////////////////////////////
// UE Numeric constants
diff --git a/src/zencore/include/zencore/iobuffer.h b/src/zencore/include/zencore/iobuffer.h
index 0cbf093ca..7accce41c 100644
--- a/src/zencore/include/zencore/iobuffer.h
+++ b/src/zencore/include/zencore/iobuffer.h
@@ -3,9 +3,9 @@
#pragma once
#include <memory.h>
+#include <zenbase/refcount.h>
#include <zencore/memory.h>
#include <atomic>
-#include "refcount.h"
#include "zencore.h"
#include <filesystem>
diff --git a/src/zencore/include/zencore/session.h b/src/zencore/include/zencore/session.h
index dd90197bf..52289b7ef 100644
--- a/src/zencore/include/zencore/session.h
+++ b/src/zencore/include/zencore/session.h
@@ -3,6 +3,7 @@
#pragma once
#include <zencore/zencore.h>
+#include <string_view>
namespace zen {
diff --git a/src/zencore/include/zencore/sharedbuffer.h b/src/zencore/include/zencore/sharedbuffer.h
index 97c5a9d21..618bd2937 100644
--- a/src/zencore/include/zencore/sharedbuffer.h
+++ b/src/zencore/include/zencore/sharedbuffer.h
@@ -4,9 +4,9 @@
#include "zencore.h"
+#include <zenbase/refcount.h>
#include <zencore/iobuffer.h>
#include <zencore/memory.h>
-#include <zencore/refcount.h>
#include <memory.h>
diff --git a/src/zencore/include/zencore/stats.h b/src/zencore/include/zencore/stats.h
index e8e08f96a..7e745dc16 100644
--- a/src/zencore/include/zencore/stats.h
+++ b/src/zencore/include/zencore/stats.h
@@ -4,6 +4,8 @@
#include "zencore.h"
+#include <zenbase/concepts.h>
+
#include <atomic>
#include <random>
diff --git a/src/zencore/include/zencore/uid.h b/src/zencore/include/zencore/uid.h
index 557567473..3abec9d16 100644
--- a/src/zencore/include/zencore/uid.h
+++ b/src/zencore/include/zencore/uid.h
@@ -3,7 +3,9 @@
#pragma once
#include <zencore/zencore.h>
+
#include <compare>
+#include <string_view>
namespace zen {
diff --git a/src/zencore/include/zencore/workthreadpool.h b/src/zencore/include/zencore/workthreadpool.h
index c10c6ed12..62356495c 100644
--- a/src/zencore/include/zencore/workthreadpool.h
+++ b/src/zencore/include/zencore/workthreadpool.h
@@ -4,7 +4,7 @@
#include <zencore/zencore.h>
-#include <zencore/refcount.h>
+#include <zenbase/refcount.h>
#include <exception>
#include <functional>
diff --git a/src/zencore/include/zencore/zencore.h b/src/zencore/include/zencore/zencore.h
index 562376c95..e8c734ba9 100644
--- a/src/zencore/include/zencore/zencore.h
+++ b/src/zencore/include/zencore/zencore.h
@@ -2,243 +2,13 @@
#pragma once
-#include <cinttypes>
+#include <zenbase/zenbase.h>
#include <stdexcept>
-#include <string>
-#include <version>
#ifndef ZEN_WITH_TESTS
# define ZEN_WITH_TESTS 1
#endif
-//////////////////////////////////////////////////////////////////////////
-// Platform
-//
-
-#define ZEN_PLATFORM_WINDOWS 0
-#define ZEN_PLATFORM_LINUX 0
-#define ZEN_PLATFORM_MAC 0
-
-#ifdef _WIN32
-# undef ZEN_PLATFORM_WINDOWS
-# define ZEN_PLATFORM_WINDOWS 1
-# define ZEN_PLATFORM_NAME "Windows"
-#elif defined(__linux__)
-# undef ZEN_PLATFORM_LINUX
-# define ZEN_PLATFORM_LINUX 1
-# define ZEN_PLATFORM_NAME "Linux"
-#elif defined(__APPLE__)
-# undef ZEN_PLATFORM_MAC
-# define ZEN_PLATFORM_MAC 1
-# define ZEN_PLATFORM_NAME "MacOS"
-#endif
-
-#if ZEN_PLATFORM_WINDOWS
-# if !defined(NOMINMAX)
-# define NOMINMAX // stops Windows.h from defining 'min/max' macros
-# endif
-# if !defined(NOGDI)
-# define NOGDI
-# endif
-# if !defined(WIN32_LEAN_AND_MEAN)
-# define WIN32_LEAN_AND_MEAN // cut-down what Windows.h defines
-# endif
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Compiler
-//
-
-#define ZEN_COMPILER_CLANG 0
-#define ZEN_COMPILER_MSC 0
-#define ZEN_COMPILER_GCC 0
-
-// Clang can define __GNUC__ and/or _MSC_VER so we check for Clang first
-#ifdef __clang__
-# undef ZEN_COMPILER_CLANG
-# define ZEN_COMPILER_CLANG 1
-#elif defined(_MSC_VER)
-# undef ZEN_COMPILER_MSC
-# define ZEN_COMPILER_MSC 1
-#elif defined(__GNUC__)
-# undef ZEN_COMPILER_GCC
-# define ZEN_COMPILER_GCC 1
-#else
-# error Unknown compiler
-#endif
-
-#if ZEN_COMPILER_MSC
-# pragma warning(disable : 4324) // warning C4324: '<type>': structure was padded due to alignment specifier
-# pragma warning(default : 4668) // warning C4668: 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
-# pragma warning(default : 4100) // warning C4100: 'identifier' : unreferenced formal parameter
-# pragma warning( \
- disable : 4373) // '%$S': virtual function overrides '%$pS', previous versions of the compiler did not override when parameters
- // only differed by const/volatile qualifiers
- // https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4373
-#endif
-
-#ifndef ZEN_THIRD_PARTY_INCLUDES_START
-# if ZEN_COMPILER_MSC
-# define ZEN_THIRD_PARTY_INCLUDES_START \
- __pragma(warning(push)) __pragma(warning(disable : 4668)) /* C4668: use of undefined preprocessor macro */ \
- __pragma(warning(disable : 4305)) /* C4305: 'if': truncation from 'uint32' to 'bool' */ \
- __pragma(warning(disable : 4267)) /* C4267: '=': conversion from 'size_t' to 'US' */ \
- __pragma(warning(disable : 4127)) /* C4127: conditional expression is constant */ \
- __pragma(warning(disable : 4189)) /* C4189: local variable is initialized but not referenced */ \
- __pragma(warning(disable : 5105)) /* C5105: macro expansion producing 'defined' has undefined behavior */
-# elif ZEN_COMPILER_CLANG
-# define ZEN_THIRD_PARTY_INCLUDES_START \
- _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wundef\"") \
- _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") _Pragma("clang diagnostic ignored \"-Wunused-variable\"")
-# elif ZEN_COMPILER_GCC
-# define ZEN_THIRD_PARTY_INCLUDES_START \
- _Pragma("GCC diagnostic push") /* NB. ignoring -Wundef doesn't work with GCC */ \
- _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
-# endif
-#endif
-
-#ifndef ZEN_THIRD_PARTY_INCLUDES_END
-# if ZEN_COMPILER_MSC
-# define ZEN_THIRD_PARTY_INCLUDES_END __pragma(warning(pop))
-# elif ZEN_COMPILER_CLANG
-# define ZEN_THIRD_PARTY_INCLUDES_END _Pragma("clang diagnostic pop")
-# elif ZEN_COMPILER_GCC
-# define ZEN_THIRD_PARTY_INCLUDES_END _Pragma("GCC diagnostic pop")
-# endif
-#endif
-
-#if ZEN_COMPILER_MSC
-# define ZEN_DEBUG_BREAK() \
- do \
- { \
- __debugbreak(); \
- } while (0)
-#else
-# define ZEN_DEBUG_BREAK() \
- do \
- { \
- __builtin_trap(); \
- } while (0)
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// C++20 support
-//
-
-// Clang
-#if ZEN_COMPILER_CLANG && __clang_major__ < 12
-# error clang-12 onwards is required for C++20 support
-#endif
-
-// GCC
-#if ZEN_COMPILER_GCC && __GNUC__ < 11
-# error GCC-11 onwards is required for C++20 support
-#endif
-
-// GNU libstdc++
-#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
-# error GNU libstdc++-11 onwards is required for C++20 support
-#endif
-
-// LLVM libc++
-#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 12000
-# error LLVM libc++-12 onwards is required for C++20 support
-#endif
-
-// At the time of writing only ver >= 13 of LLVM's libc++ has an implementation
-// of std::integral. Some platforms like Ubuntu and Mac OS are still on 12.
-#if defined(__cpp_lib_concepts)
-# include <concepts>
-template<class T>
-concept Integral = std::integral<T>;
-template<class T>
-concept SignedIntegral = std::signed_integral<T>;
-template<class T>
-concept UnsignedIntegral = std::unsigned_integral<T>;
-template<class F, class... A>
-concept Invocable = std::invocable<F, A...>;
-template<class D, class B>
-concept DerivedFrom = std::derived_from<D, B>;
-#else
-template<class T>
-concept Integral = std::is_integral_v<T>;
-template<class T>
-concept SignedIntegral = Integral<T> && std::is_signed_v<T>;
-template<class T>
-concept UnsignedIntegral = Integral<T> && !std::is_signed_v<T>;
-template<class F, class... A>
-concept Invocable = requires(F&& f, A&&... a)
-{
- std::invoke(std::forward<F>(f), std::forward<A>(a)...);
-};
-template<class D, class B>
-concept DerivedFrom = std::is_base_of_v<B, D> && std::is_convertible_v<const volatile D*, const volatile B*>;
-#endif
-
-#if defined(__cpp_lib_ranges)
-template<typename T>
-concept ContiguousRange = std::ranges::contiguous_range<T>;
-#else
-template<typename T>
-concept ContiguousRange = true;
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Architecture
-//
-
-#if defined(__amd64__) || defined(_M_X64)
-# define ZEN_ARCH_X64 1
-# define ZEN_ARCH_ARM64 0
-#elif defined(__arm64__) || defined(_M_ARM64)
-# define ZEN_ARCH_X64 0
-# define ZEN_ARCH_ARM64 1
-#else
-# error Unknown architecture
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Build flavor
-//
-
-#ifdef NDEBUG
-# define ZEN_BUILD_DEBUG 0
-# define ZEN_BUILD_RELEASE 1
-# define ZEN_BUILD_NAME "release"
-#else
-# define ZEN_BUILD_DEBUG 1
-# define ZEN_BUILD_RELEASE 0
-# define ZEN_BUILD_NAME "debug"
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-
-#define ZEN_PLATFORM_SUPPORTS_UNALIGNED_LOADS 1
-
-#if defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 4
-# define ZEN_SIZEOF_WCHAR_T 4
-#else
-static_assert(sizeof(wchar_t) == 2, "wchar_t is expected to be two bytes in size");
-# define ZEN_SIZEOF_WCHAR_T 2
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Assert
-//
-
-#if ZEN_PLATFORM_WINDOWS
-// Tells the compiler to put the decorated function in a certain section (aka. segment) of the executable.
-# define ZEN_CODE_SECTION(Name) __declspec(code_seg(Name))
-# define ZEN_DATA_SECTION(Name) __declspec(allocate(Name))
-# define ZEN_FORCENOINLINE __declspec(noinline) /* Force code to NOT be inline */
-# define LINE_TERMINATOR_ANSI "\r\n"
-#else
-# define ZEN_CODE_SECTION(Name)
-# define ZEN_DATA_SECTION(Name)
-# define ZEN_FORCENOINLINE
-# define LINE_TERMINATOR_ANSI "\n"
-#endif
-
#if ZEN_ARCH_ARM64
// On ARM we can't do this because the executable will require jumps larger
// than the branch instruction can handle. Clang will only generate
@@ -253,37 +23,36 @@ static_assert(sizeof(wchar_t) == 2, "wchar_t is expected to be two bytes in size
# define ZEN_DEBUG_SECTION ZEN_CODE_SECTION(".zcold")
#endif
-namespace zen
+namespace zen {
+class AssertException : public std::logic_error
{
- class AssertException : public std::logic_error
- {
- public:
- inline explicit AssertException(const char* Msg) : std::logic_error(Msg) {}
- };
+public:
+ inline explicit AssertException(const char* Msg) : std::logic_error(Msg) {}
+};
- struct AssertImpl
+struct AssertImpl
+{
+ static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecAssert
+ [[noreturn]] (const char* Filename, int LineNumber, const char* FunctionName, const char* Msg)
{
- static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecAssert
- [[noreturn]] (const char* Filename, int LineNumber, const char* FunctionName, const char* Msg)
- {
- CurrentAssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg);
- throw AssertException{Msg};
- }
-
- protected:
- virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename,
- int LineNumber,
- const char* FunctionName,
- const char* Msg)
- {
- (void(Filename));
- (void(LineNumber));
- (void(FunctionName));
- (void(Msg));
- }
- static AssertImpl DefaultAssertImpl;
- static AssertImpl* CurrentAssertImpl;
- };
+ CurrentAssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg);
+ throw AssertException{Msg};
+ }
+
+protected:
+ virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename,
+ int LineNumber,
+ const char* FunctionName,
+ const char* Msg)
+ {
+ (void(Filename));
+ (void(LineNumber));
+ (void(FunctionName));
+ (void(Msg));
+ }
+ static AssertImpl DefaultAssertImpl;
+ static AssertImpl* CurrentAssertImpl;
+};
} // namespace zen
@@ -309,31 +78,6 @@ namespace zen
//////////////////////////////////////////////////////////////////////////
-#ifdef __clang__
-template<typename T>
-auto ZenArrayCountHelper(T& t) -> typename std::enable_if<__is_array(T), char (&)[sizeof(t) / sizeof(t[0]) + 1]>::type;
-#else
-template<typename T, uint32_t N>
-char (&ZenArrayCountHelper(const T (&)[N]))[N + 1];
-#endif
-
-#define ZEN_ARRAY_COUNT(array) (sizeof(ZenArrayCountHelper(array)) - 1)
-
-//////////////////////////////////////////////////////////////////////////
-
-#if ZEN_COMPILER_MSC
-# define ZEN_NOINLINE __declspec(noinline)
-#else
-# define ZEN_NOINLINE __attribute__((noinline))
-#endif
-
-#if ZEN_PLATFORM_WINDOWS
-# define ZEN_EXE_SUFFIX_LITERAL ".exe"
-#else
-# define ZEN_EXE_SUFFIX_LITERAL ""
-#endif
-
-#define ZEN_UNUSED(...) ((void)__VA_ARGS__)
#define ZEN_NOT_IMPLEMENTED(...) ZEN_ASSERT(false, __VA_ARGS__)
#define ZENCORE_API // Placeholder to allow DLL configs in the future (maybe)
@@ -363,30 +107,6 @@ ZENCORE_API void zencore_forcelinktests();
//////////////////////////////////////////////////////////////////////////
-#if ZEN_COMPILER_MSC
-# define ZEN_DISABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", off))
-# define ZEN_ENABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", on))
-#elif ZEN_COMPILER_GCC
-# define ZEN_DISABLE_OPTIMIZATION_ACTUAL _Pragma("GCC push_options") _Pragma("GCC optimize (\"O0\")")
-# define ZEN_ENABLE_OPTIMIZATION_ACTUAL _Pragma("GCC pop_options")
-#elif ZEN_COMPILER_CLANG
-# define ZEN_DISABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize off")
-# define ZEN_ENABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize on")
-#endif
-
-// Set up optimization control macros, now that we have both the build settings and the platform macros
-#define ZEN_DISABLE_OPTIMIZATION ZEN_DISABLE_OPTIMIZATION_ACTUAL
-
-#if ZEN_BUILD_DEBUG
-# define ZEN_ENABLE_OPTIMIZATION ZEN_DISABLE_OPTIMIZATION_ACTUAL
-#else
-# define ZEN_ENABLE_OPTIMIZATION ZEN_ENABLE_OPTIMIZATION_ACTUAL
-#endif
-
-#define ZEN_ENABLE_OPTIMIZATION_ALWAYS ZEN_ENABLE_OPTIMIZATION_ACTUAL
-
-//////////////////////////////////////////////////////////////////////////
-
#ifndef ZEN_WITH_TRACE
# define ZEN_WITH_TRACE 0
#endif
diff --git a/src/zencore/refcount.cpp b/src/zencore/refcount.cpp
index c6c47b04d..a6a86ee12 100644
--- a/src/zencore/refcount.cpp
+++ b/src/zencore/refcount.cpp
@@ -1,6 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
-#include <zencore/refcount.h>
+#include <zenbase/refcount.h>
#include <zencore/testing.h>
diff --git a/src/zencore/xmake.lua b/src/zencore/xmake.lua
index 37609f0d1..51ee0eb75 100644
--- a/src/zencore/xmake.lua
+++ b/src/zencore/xmake.lua
@@ -28,6 +28,7 @@ target('zencore')
add_links("oo2coremac64")
end
add_options("zentrace")
+ add_deps("zenbase")
add_packages(
"vcpkg::blake3",
"vcpkg::doctest",
diff --git a/src/zencore/zencore.cpp b/src/zencore/zencore.cpp
index 84ffee45b..9377a733b 100644
--- a/src/zencore/zencore.cpp
+++ b/src/zencore/zencore.cpp
@@ -24,7 +24,6 @@
#include <zencore/logging.h>
#include <zencore/memory.h>
#include <zencore/mpscqueue.h>
-#include <zencore/refcount.h>
#include <zencore/sha1.h>
#include <zencore/stats.h>
#include <zencore/stream.h>
@@ -36,6 +35,8 @@
namespace zen {
+void refcount_forcelink();
+
AssertImpl AssertImpl::DefaultAssertImpl;
AssertImpl* AssertImpl::CurrentAssertImpl = &AssertImpl::DefaultAssertImpl;
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp
index aa8bdddd6..9c303c62d 100644
--- a/src/zenhttp/httpserver.cpp
+++ b/src/zenhttp/httpserver.cpp
@@ -14,12 +14,12 @@
# include "transports/winsocktransport.h"
#endif
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
#include <zencore/compactbinarybuilder.h>
#include <zencore/compactbinarypackage.h>
#include <zencore/iobuffer.h>
#include <zencore/logging.h>
-#include <zencore/refcount.h>
#include <zencore/stream.h>
#include <zencore/string.h>
#include <zencore/testing.h>
diff --git a/src/zenhttp/include/zenhttp/httpplugin.h b/src/zenhttp/include/zenhttp/httpplugin.h
index 30a66e92e..5feccfcba 100644
--- a/src/zenhttp/include/zenhttp/httpplugin.h
+++ b/src/zenhttp/include/zenhttp/httpplugin.h
@@ -2,7 +2,7 @@
#pragma once
-#include <zencore/refcount.h>
+#include <zenbase/refcount.h>
#if !defined(ZEN_WITH_PLUGINS)
# if ZEN_PLATFORM_WINDOWS
diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h
index 3cbe05dd6..5d01e380a 100644
--- a/src/zenhttp/include/zenhttp/httpserver.h
+++ b/src/zenhttp/include/zenhttp/httpserver.h
@@ -4,11 +4,11 @@
#include "zenhttp.h"
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
#include <zencore/enumflags.h>
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
-#include <zencore/refcount.h>
#include <zencore/string.h>
#include <zencore/uid.h>
#include <zenhttp/httpcommon.h>
diff --git a/src/zenserver-test/projectclient.h b/src/zenserver-test/projectclient.h
index 1865dd67d..8362ee0ee 100644
--- a/src/zenserver-test/projectclient.h
+++ b/src/zenserver-test/projectclient.h
@@ -4,8 +4,8 @@
#include <memory>
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
-#include <zencore/refcount.h>
namespace zen {
diff --git a/src/zenserver-test/zenserver-test.cpp b/src/zenserver-test/zenserver-test.cpp
index 9df683701..34f058807 100644
--- a/src/zenserver-test/zenserver-test.cpp
+++ b/src/zenserver-test/zenserver-test.cpp
@@ -2,6 +2,7 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
#include <zencore/compactbinarybuilder.h>
#include <zencore/compactbinarypackage.h>
@@ -12,7 +13,6 @@
#include <zencore/iohash.h>
#include <zencore/logging.h>
#include <zencore/memory.h>
-#include <zencore/refcount.h>
#include <zencore/stream.h>
#include <zencore/string.h>
#include <zencore/testutils.h>
diff --git a/src/zenserver/upstream/jupiter.h b/src/zenserver/upstream/jupiter.h
index 467f28501..b5aa95ed5 100644
--- a/src/zenserver/upstream/jupiter.h
+++ b/src/zenserver/upstream/jupiter.h
@@ -2,9 +2,9 @@
#pragma once
+#include <zenbase/refcount.h>
#include <zencore/iohash.h>
#include <zencore/logging.h>
-#include <zencore/refcount.h>
#include <zencore/thread.h>
#include <zenhttp/httpserver.h>
diff --git a/src/zenserver/vfs/vfsservice.h b/src/zenserver/vfs/vfsservice.h
index 9510cfcda..dcdc71e81 100644
--- a/src/zenserver/vfs/vfsservice.h
+++ b/src/zenserver/vfs/vfsservice.h
@@ -2,7 +2,7 @@
#pragma once
-#include <zencore/refcount.h>
+#include <zenbase/refcount.h>
#include <zenhttp/httpserver.h>
#include <zenvfs/vfs.h>
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 282dc73cf..1a0e1bdde 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -4,6 +4,7 @@
#include "sentryintegration.h"
+#include <zenbase/refcount.h>
#include <zencore/compactbinarybuilder.h>
#include <zencore/compactbinaryvalidation.h>
#include <zencore/config.h>
@@ -12,7 +13,6 @@
#include <zencore/iobuffer.h>
#include <zencore/jobqueue.h>
#include <zencore/logging.h>
-#include <zencore/refcount.h>
#include <zencore/scopeguard.h>
#include <zencore/session.h>
#include <zencore/string.h>
diff --git a/src/zenutil/include/zenutil/cache/cachepolicy.h b/src/zenutil/include/zenutil/cache/cachepolicy.h
index 9a745e42c..c9c9e78a4 100644
--- a/src/zenutil/include/zenutil/cache/cachepolicy.h
+++ b/src/zenutil/include/zenutil/cache/cachepolicy.h
@@ -2,9 +2,9 @@
#pragma once
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
#include <zencore/enumflags.h>
-#include <zencore/refcount.h>
#include <zencore/string.h>
#include <zencore/uid.h>
diff --git a/src/zenutil/include/zenutil/statsreporter.h b/src/zenutil/include/zenutil/statsreporter.h
index a25e5d353..eec5699b2 100644
--- a/src/zenutil/include/zenutil/statsreporter.h
+++ b/src/zenutil/include/zenutil/statsreporter.h
@@ -4,6 +4,8 @@
#include <zencore/zencore.h>
+#include <string_view>
+
namespace zen {
class StatsProvider;
diff --git a/src/zenvfs/include/zenvfs/vfs.h b/src/zenvfs/include/zenvfs/vfs.h
index 412970860..6da9697a1 100644
--- a/src/zenvfs/include/zenvfs/vfs.h
+++ b/src/zenvfs/include/zenvfs/vfs.h
@@ -7,7 +7,7 @@
#if ZEN_WITH_VFS
# include <zencore/zencore.h>
-# include <zencore/refcount.h>
+# include <zenbase/refcount.h>
# include <zencore/uid.h>
# include <string_view>