This is an automated email from the ASF dual-hosted git repository.
jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 4d2ca6b1 fix ALIGNAS/ALIGNOF/BAIDU_CACHELINE_ALIGMENT
4d2ca6b1 is described below
commit 4d2ca6b1e4fba37cfea80d6855087aafe63a4099
Author: gejun.0 <[email protected]>
AuthorDate: Fri Aug 26 18:49:38 2022 +0800
fix ALIGNAS/ALIGNOF/BAIDU_CACHELINE_ALIGMENT
---
src/brpc/policy/auto_concurrency_limiter.h | 4 ++--
src/brpc/server.h | 3 +--
src/bthread/execution_queue_inl.h | 6 ++---
src/bthread/mutex.cpp | 2 +-
src/bthread/work_stealing_queue.h | 2 +-
src/butil/compiler_specific.h | 36 ++++++++++++++----------------
6 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/src/brpc/policy/auto_concurrency_limiter.h
b/src/brpc/policy/auto_concurrency_limiter.h
index 751e8337..7d694247 100644
--- a/src/brpc/policy/auto_concurrency_limiter.h
+++ b/src/brpc/policy/auto_concurrency_limiter.h
@@ -73,12 +73,12 @@ private:
double _explore_ratio;
// modified per sample.
- butil::atomic<int64_t> BAIDU_CACHELINE_ALIGNMENT _last_sampling_time_us;
+ BAIDU_CACHELINE_ALIGNMENT butil::atomic<int64_t> _last_sampling_time_us;
butil::Mutex _sw_mutex;
SampleWindow _sw;
// modified per request.
- butil::atomic<int32_t> BAIDU_CACHELINE_ALIGNMENT _total_succ_req;
+ BAIDU_CACHELINE_ALIGNMENT butil::atomic<int32_t> _total_succ_req;
};
} // namespace policy
diff --git a/src/brpc/server.h b/src/brpc/server.h
index 8c7a3959..261bfdce 100644
--- a/src/brpc/server.h
+++ b/src/brpc/server.h
@@ -691,8 +691,7 @@ friend class Controller;
// mutable is required for `ServerPrivateAccessor' to change this bvar
mutable bvar::Adder<int64_t> _nerror_bvar;
mutable bvar::PerSecond<bvar::Adder<int64_t> > _eps_bvar;
- mutable int32_t BAIDU_CACHELINE_ALIGNMENT _concurrency;
-
+ BAIDU_CACHELINE_ALIGNMENT mutable int32_t _concurrency;
};
// Get the data attached to current searching thread. The data is created by
diff --git a/src/bthread/execution_queue_inl.h
b/src/bthread/execution_queue_inl.h
index 20fdab24..a346786d 100644
--- a/src/bthread/execution_queue_inl.h
+++ b/src/bthread/execution_queue_inl.h
@@ -223,9 +223,9 @@ private:
// Don't change the order of _head, _versioned_ref and _stopped unless you
// see improvement of performance in test
- butil::atomic<TaskNode*> BAIDU_CACHELINE_ALIGNMENT _head;
- butil::atomic<uint64_t> BAIDU_CACHELINE_ALIGNMENT _versioned_ref;
- butil::atomic<bool> BAIDU_CACHELINE_ALIGNMENT _stopped;
+ BAIDU_CACHELINE_ALIGNMENT butil::atomic<TaskNode*> _head;
+ BAIDU_CACHELINE_ALIGNMENT butil::atomic<uint64_t> _versioned_ref;
+ BAIDU_CACHELINE_ALIGNMENT butil::atomic<bool> _stopped;
butil::atomic<int64_t> _high_priority_tasks;
uint64_t _this_id;
void* _meta;
diff --git a/src/bthread/mutex.cpp b/src/bthread/mutex.cpp
index e044eae2..f0dfc044 100644
--- a/src/bthread/mutex.cpp
+++ b/src/bthread/mutex.cpp
@@ -253,7 +253,7 @@ void ContentionProfiler::flush_to_disk(bool ending) {
// If contention profiler is on, this variable will be set with a valid
// instance. NULL otherwise.
-static ContentionProfiler* BAIDU_CACHELINE_ALIGNMENT g_cp = NULL;
+BAIDU_CACHELINE_ALIGNMENT static ContentionProfiler* g_cp = NULL;
// Need this version to solve an issue that non-empty entries left by
// previous contention profilers should be detected and overwritten.
static uint64_t g_cp_version = 0;
diff --git a/src/bthread/work_stealing_queue.h
b/src/bthread/work_stealing_queue.h
index 3750ac5e..357f1414 100644
--- a/src/bthread/work_stealing_queue.h
+++ b/src/bthread/work_stealing_queue.h
@@ -149,7 +149,7 @@ private:
butil::atomic<size_t> _bottom;
size_t _capacity;
T* _buffer;
- butil::atomic<size_t> BAIDU_CACHELINE_ALIGNMENT _top;
+ BAIDU_CACHELINE_ALIGNMENT butil::atomic<size_t> _top;
};
} // namespace bthread
diff --git a/src/butil/compiler_specific.h b/src/butil/compiler_specific.h
index 36fb651c..9da98a4a 100644
--- a/src/butil/compiler_specific.h
+++ b/src/butil/compiler_specific.h
@@ -124,10 +124,14 @@
// Use like:
// class ALIGNAS(16) MyClass { ... }
// ALIGNAS(16) int array[4];
-#if defined(COMPILER_MSVC)
-#define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
-#elif defined(COMPILER_GCC)
-#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
+#if defined(BUTIL_CXX11_ENABLED)
+# define ALIGNAS(byte_alignment) alignas(byte_alignment)
+#else
+# if defined(COMPILER_MSVC)
+# define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
+# elif defined(COMPILER_GCC)
+# define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
+# endif
#endif
// Return the byte alignment of the given type (available at compile time).
Use
@@ -135,10 +139,14 @@
// http://goo.gl/isH0C
// Use like:
// ALIGNOF(int32_t) // this would be 4
-#if defined(COMPILER_MSVC)
-#define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
-#elif defined(COMPILER_GCC)
-#define ALIGNOF(type) __alignof__(type)
+#if defined(BUTIL_CXX11_ENABLED)
+# define ALIGNOF(type) alignof(type)
+#else
+# if defined(COMPILER_MSVC)
+# define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
+# elif defined(COMPILER_GCC)
+# define ALIGNOF(type) __alignof__(type)
+# endif
#endif
// Annotate a virtual method indicating it must be overriding a virtual
@@ -259,17 +267,7 @@
// Cacheline related --------------------------------------
#define BAIDU_CACHELINE_SIZE 64
-#ifdef _MSC_VER
-# define BAIDU_CACHELINE_ALIGNMENT __declspec(align(BAIDU_CACHELINE_SIZE))
-#endif /* _MSC_VER */
-
-#ifdef __GNUC__
-# define BAIDU_CACHELINE_ALIGNMENT
__attribute__((aligned(BAIDU_CACHELINE_SIZE)))
-#endif /* __GNUC__ */
-
-#ifndef BAIDU_CACHELINE_ALIGNMENT
-# define BAIDU_CACHELINE_ALIGNMENT /*BAIDU_CACHELINE_ALIGNMENT*/
-#endif
+#define BAIDU_CACHELINE_ALIGNMENT ALIGNAS(BAIDU_CACHELINE_SIZE)
#ifndef BAIDU_NOEXCEPT
# if defined(BUTIL_CXX11_ENABLED)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]