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

add [email protected] to registry #75

Merged
merged 1 commit into from
Nov 4, 2024
Merged
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
31 changes: 31 additions & 0 deletions registry/modules/brpc/1.11.0/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module(
name = 'brpc',
version = '1.11.0',
compatibility_level = 1,
)

# --registry=https://bcr.bazel.build
bazel_dep(name = 'abseil-cpp', version = '20210324.2', repo_name = 'com_google_absl')
bazel_dep(name = 'bazel_skylib', version = '1.0.3')
bazel_dep(name = 'boringssl', version = '0.0.0-20211025-d4f1ab9')
bazel_dep(name = 'protobuf', version = '3.19.6', repo_name = 'com_google_protobuf')
bazel_dep(name = 'gflags', version = '2.2.2', repo_name = 'com_github_gflags_gflags')
bazel_dep(name = 'glog', version = '0.5.0', repo_name = 'com_github_google_glog')
bazel_dep(name = 'platforms', version = '0.0.4')
bazel_dep(name = 'rules_cc', version = '0.0.1')
bazel_dep(name = 'rules_proto', version = '4.0.0')
bazel_dep(name = 'zlib', version = '1.2.13', repo_name = 'com_github_madler_zlib')

# --registry=https://baidu.github.io/babylon/registry
bazel_dep(name = 'leveldb', version = '1.23', repo_name = 'com_github_google_leveldb')
bazel_dep(name = 'openssl', version = '3.3.2')
bazel_dep(name = 'thrift', version = '0.21.0', repo_name = 'org_apache_thrift')

# test only
bazel_dep(name = 'googletest', version = '1.14.0.bcr.1', repo_name = 'com_google_googletest', dev_dependency = True)
bazel_dep(name = 'hedron_compile_commands', dev_dependency = True)
git_override(
module_name = 'hedron_compile_commands',
remote = 'https://github.com/hedronvision/bazel-compile-commands-extractor.git',
commit = '1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93', # Jun 28, 2024
)
5 changes: 5 additions & 0 deletions registry/modules/brpc/1.11.0/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"url": "https://github.com/apache/brpc/archive/refs/tags/1.11.0.tar.gz",
"strip_prefix": "brpc-1.11.0",
"integrity": "sha256-74flQ6ULckbOgzBlqGEIT4wypOInNptEBfIl+CqNMDA="
}
75 changes: 66 additions & 9 deletions src/babylon/concurrent/thread_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@ class EnumerableThreadLocal {
public:
// 可默认构造,可以移动,不能拷贝
EnumerableThreadLocal() noexcept;
inline EnumerableThreadLocal(EnumerableThreadLocal&&) noexcept = default;
EnumerableThreadLocal(EnumerableThreadLocal&&) noexcept;
EnumerableThreadLocal(const EnumerableThreadLocal&) = delete;
inline EnumerableThreadLocal& operator=(EnumerableThreadLocal&&) noexcept =
default;
EnumerableThreadLocal& operator=(EnumerableThreadLocal&&) noexcept;
EnumerableThreadLocal& operator=(const EnumerableThreadLocal&) = delete;

template <typename C>
EnumerableThreadLocal(C&& constructor) noexcept;

void set_constructor(::std::function<void(T*)> constructor) noexcept {
_storage.set_constructor(constructor);
}
void set_constructor(::std::function<void(T*)> constructor) noexcept;

// 获得线程局部存储
inline T& local() {
return _storage.ensure(ThreadId::current_thread_id<T>().value);
}
inline T& local();

// 遍历所有【当前或曾经存在】的线程局部存储
template <typename C, typename = typename ::std::enable_if<
Expand Down Expand Up @@ -76,7 +71,20 @@ class EnumerableThreadLocal {
}

private:
struct Cache;

static size_t fetch_add_id() noexcept;

inline T& local_slow(Cache& cache);

ConcurrentVector<T, 128> _storage;
size_t _id {fetch_add_id()};
};

template <typename T>
struct EnumerableThreadLocal<T>::Cache {
size_t id {0};
T* item {nullptr};
};

// 典型线程局部存储为了性能一般会独占缓存行
Expand Down Expand Up @@ -162,12 +170,29 @@ class CompactEnumerableThreadLocal {
Storage* _storage;
};

////////////////////////////////////////////////////////////////////////////////
// EnumerableThreadLocal begin
template <typename T>
inline EnumerableThreadLocal<T>::EnumerableThreadLocal() noexcept {
// 确保内部使用的ThreadId此时初始化,建立正确的析构顺序
ThreadId::end<T>();
}

template <typename T>
EnumerableThreadLocal<T>::EnumerableThreadLocal(
EnumerableThreadLocal&& other) noexcept
: EnumerableThreadLocal {} {
*this = ::std::move(other);
}

template <typename T>
EnumerableThreadLocal<T>& EnumerableThreadLocal<T>::operator=(
EnumerableThreadLocal&& other) noexcept {
::std::swap(_id, other._id);
::std::swap(_storage, other._storage);
return *this;
}

template <typename T>
template <typename C>
inline EnumerableThreadLocal<T>::EnumerableThreadLocal(C&& constructor) noexcept
Expand All @@ -176,6 +201,38 @@ inline EnumerableThreadLocal<T>::EnumerableThreadLocal(C&& constructor) noexcept
ThreadId::end<T>();
}

template <typename T>
ABSL_ATTRIBUTE_NOINLINE void EnumerableThreadLocal<T>::set_constructor(
::std::function<void(T*)> constructor) noexcept {
_storage.set_constructor(constructor);
}

template <typename T>
ABSL_ATTRIBUTE_ALWAYS_INLINE inline T& EnumerableThreadLocal<T>::local() {
static thread_local Cache cache;
if (ABSL_PREDICT_TRUE(cache.id == _id)) {
return *cache.item;
}
return local_slow(cache);
}

template <typename T>
ABSL_ATTRIBUTE_NOINLINE size_t
EnumerableThreadLocal<T>::fetch_add_id() noexcept {
static ::std::atomic<size_t> next_id {1};
return next_id.fetch_add(1, ::std::memory_order_relaxed);
}

template <typename T>
inline T& EnumerableThreadLocal<T>::local_slow(Cache& cache) {
auto& item = _storage.ensure(ThreadId::current_thread_id<T>().value);
cache.id = _id;
cache.item = &item;
return item;
}
// EnumerableThreadLocal end
////////////////////////////////////////////////////////////////////////////////

template <typename T, size_t CACHE_LINE_NUM>
CompactEnumerableThreadLocal<
T, CACHE_LINE_NUM>::CompactEnumerableThreadLocal() noexcept
Expand Down
22 changes: 12 additions & 10 deletions src/babylon/reusable/patch/arena.25.0.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ constexpr size_t kAllocPolicyWithMemoryResourcePointerSize =
ArenaAlignDefault::Ceil(sizeof(AllocationPolicyWithMemoryResourcePointer));

inline PROTOBUF_ALWAYS_INLINE bool use_swiss_resource(const AllocationPolicy* policy) noexcept {
return policy != nullptr
&& policy->block_alloc == ::babylon::SwissMemoryResource::arena_block_alloc;
if (policy != nullptr) {
return policy->block_alloc == ::babylon::SwissMemoryResource::arena_block_alloc;
}
return false;
}

inline PROTOBUF_ALWAYS_INLINE AllocationPolicyWithMemoryResourcePointer::SwissMemoryResource&
Expand Down Expand Up @@ -225,8 +227,8 @@ void* SerialArena::AllocateAlignedFallback(size_t n) {

PROTOBUF_NOINLINE
void* SerialArena::AllocateFromStringBlockFallback() {
if (internal::use_swiss_resource(parent_.AllocPolicy())) {
auto& resource = internal::swiss_resource(parent_.AllocPolicy());
if (ABSL_PREDICT_TRUE(use_swiss_resource(parent_.AllocPolicy()))) {
auto& resource = swiss_resource(parent_.AllocPolicy());
auto ptr = reinterpret_cast<::std::string*>(
resource.allocate<alignof(std::string)>(sizeof(std::string)));
resource.register_destructor(ptr);
Expand Down Expand Up @@ -806,7 +808,7 @@ void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align,
}

void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) {
if (use_swiss_resource(AllocPolicy())) {
if (ABSL_PREDICT_TRUE(use_swiss_resource(AllocPolicy()))) {
swiss_resource(AllocPolicy()).do_register_destructor(elem, cleanup);
return;
}
Expand All @@ -830,8 +832,8 @@ void* ThreadSafeArena::AllocateAlignedWithCleanupFallback(

PROTOBUF_NOINLINE
void* ThreadSafeArena::AllocateFromStringBlock() {
if (internal::use_swiss_resource(AllocPolicy())) {
auto& resource = internal::swiss_resource(AllocPolicy());
if (ABSL_PREDICT_TRUE(use_swiss_resource(AllocPolicy()))) {
auto& resource = swiss_resource(AllocPolicy());
auto ptr = resource.allocate<alignof(::std::string)>(sizeof(::std::string));
resource.register_destructor<::std::string>(static_cast<::std::string*>(ptr));
return ptr;
Expand Down Expand Up @@ -960,22 +962,22 @@ SerialArena* ThreadSafeArena::GetSerialArenaFallback(size_t n) {
} // namespace internal

void* Arena::Allocate(size_t n) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
return internal::swiss_resource(impl_.AllocPolicy()).allocate<8>(n);
}
return impl_.AllocateAligned(n);
}

void* Arena::AllocateForArray(size_t n) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
return internal::swiss_resource(impl_.AllocPolicy()).allocate<8>(n);
}
return impl_.AllocateAligned<internal::AllocationClient::kArray>(n);
}

void* Arena::AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*)) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
auto& resource = internal::swiss_resource(impl_.AllocPolicy());
auto ptr = resource.allocate<8>(n);
resource.do_register_destructor(ptr, destructor);
Expand Down
22 changes: 12 additions & 10 deletions src/babylon/reusable/patch/arena.27.0.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ constexpr size_t kAllocPolicyWithMemoryResourcePointerSize =
ArenaAlignDefault::Ceil(sizeof(AllocationPolicyWithMemoryResourcePointer));

inline PROTOBUF_ALWAYS_INLINE bool use_swiss_resource(const AllocationPolicy* policy) noexcept {
return policy != nullptr
&& policy->block_alloc == ::babylon::SwissMemoryResource::arena_block_alloc;
if (policy != nullptr) {
return policy->block_alloc == ::babylon::SwissMemoryResource::arena_block_alloc;
}
return false;
}

inline PROTOBUF_ALWAYS_INLINE AllocationPolicyWithMemoryResourcePointer::SwissMemoryResource&
Expand Down Expand Up @@ -219,8 +221,8 @@ void* SerialArena::AllocateAlignedFallback(size_t n) {

PROTOBUF_NOINLINE
void* SerialArena::AllocateFromStringBlockFallback() {
if (internal::use_swiss_resource(parent_.AllocPolicy())) {
auto& resource = internal::swiss_resource(parent_.AllocPolicy());
if (ABSL_PREDICT_TRUE(use_swiss_resource(parent_.AllocPolicy()))) {
auto& resource = swiss_resource(parent_.AllocPolicy());
auto ptr = reinterpret_cast<::std::string*>(
resource.allocate<alignof(std::string)>(sizeof(std::string)));
resource.register_destructor(ptr);
Expand Down Expand Up @@ -809,7 +811,7 @@ void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align,
}

void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) {
if (use_swiss_resource(AllocPolicy())) {
if (ABSL_PREDICT_TRUE(use_swiss_resource(AllocPolicy()))) {
swiss_resource(AllocPolicy()).do_register_destructor(elem, cleanup);
return;
}
Expand All @@ -833,8 +835,8 @@ void* ThreadSafeArena::AllocateAlignedWithCleanupFallback(

PROTOBUF_NOINLINE
void* ThreadSafeArena::AllocateFromStringBlock() {
if (internal::use_swiss_resource(AllocPolicy())) {
auto& resource = internal::swiss_resource(AllocPolicy());
if (ABSL_PREDICT_TRUE(use_swiss_resource(AllocPolicy()))) {
auto& resource = swiss_resource(AllocPolicy());
auto ptr = resource.allocate<alignof(::std::string)>(sizeof(::std::string));
resource.register_destructor<::std::string>(static_cast<::std::string*>(ptr));
return ptr;
Expand Down Expand Up @@ -974,22 +976,22 @@ SerialArena* ThreadSafeArena::GetSerialArenaFallback(size_t n) {
} // namespace internal

void* Arena::Allocate(size_t n) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
return internal::swiss_resource(impl_.AllocPolicy()).allocate<8>(n);
}
return impl_.AllocateAligned(n);
}

void* Arena::AllocateForArray(size_t n) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
return internal::swiss_resource(impl_.AllocPolicy()).allocate<8>(n);
}
return impl_.AllocateAligned<internal::AllocationClient::kArray>(n);
}

void* Arena::AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*)) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
auto& resource = internal::swiss_resource(impl_.AllocPolicy());
auto ptr = resource.allocate<8>(n);
resource.do_register_destructor(ptr, destructor);
Expand Down
22 changes: 12 additions & 10 deletions src/babylon/reusable/patch/arena.28.0.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ constexpr size_t kAllocPolicyWithMemoryResourcePointerSize =
ArenaAlignDefault::Ceil(sizeof(AllocationPolicyWithMemoryResourcePointer));

inline PROTOBUF_ALWAYS_INLINE bool use_swiss_resource(const AllocationPolicy* policy) noexcept {
return policy != nullptr
&& policy->block_alloc == ::babylon::SwissMemoryResource::arena_block_alloc;
if (policy != nullptr) {
return policy->block_alloc == ::babylon::SwissMemoryResource::arena_block_alloc;
}
return false;
}

inline PROTOBUF_ALWAYS_INLINE AllocationPolicyWithMemoryResourcePointer::SwissMemoryResource&
Expand Down Expand Up @@ -297,8 +299,8 @@ void* SerialArena::AllocateAlignedFallback(size_t n) {

PROTOBUF_NOINLINE
void* SerialArena::AllocateFromStringBlockFallback() {
if (internal::use_swiss_resource(parent_.AllocPolicy())) {
auto& resource = internal::swiss_resource(parent_.AllocPolicy());
if (ABSL_PREDICT_TRUE(use_swiss_resource(parent_.AllocPolicy()))) {
auto& resource = swiss_resource(parent_.AllocPolicy());
auto ptr = reinterpret_cast<::std::string*>(
resource.allocate<alignof(std::string)>(sizeof(std::string)));
resource.register_destructor(ptr);
Expand Down Expand Up @@ -856,7 +858,7 @@ void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align,
}

void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) {
if (use_swiss_resource(AllocPolicy())) {
if (ABSL_PREDICT_TRUE(use_swiss_resource(AllocPolicy()))) {
swiss_resource(AllocPolicy()).do_register_destructor(elem, cleanup);
return;
}
Expand All @@ -880,8 +882,8 @@ void* ThreadSafeArena::AllocateAlignedWithCleanupFallback(

PROTOBUF_NOINLINE
void* ThreadSafeArena::AllocateFromStringBlock() {
if (internal::use_swiss_resource(AllocPolicy())) {
auto& resource = internal::swiss_resource(AllocPolicy());
if (ABSL_PREDICT_TRUE(use_swiss_resource(AllocPolicy()))) {
auto& resource = swiss_resource(AllocPolicy());
auto ptr = resource.allocate<alignof(::std::string)>(sizeof(::std::string));
resource.register_destructor<::std::string>(static_cast<::std::string*>(ptr));
return ptr;
Expand Down Expand Up @@ -1021,22 +1023,22 @@ SerialArena* ThreadSafeArena::GetSerialArenaFallback(size_t n) {
} // namespace internal

void* Arena::Allocate(size_t n) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
return internal::swiss_resource(impl_.AllocPolicy()).allocate<8>(n);
}
return impl_.AllocateAligned(n);
}

void* Arena::AllocateForArray(size_t n) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
return internal::swiss_resource(impl_.AllocPolicy()).allocate<8>(n);
}
return impl_.AllocateAligned<internal::AllocationClient::kArray>(n);
}

void* Arena::AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*)) {
if (internal::use_swiss_resource(impl_.AllocPolicy())) {
if (ABSL_PREDICT_TRUE(internal::use_swiss_resource(impl_.AllocPolicy()))) {
auto& resource = internal::swiss_resource(impl_.AllocPolicy());
auto ptr = resource.allocate<8>(n);
resource.do_register_destructor(ptr, destructor);
Expand Down
Loading