Skip to content

Commit 6df9cf6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 19d8615 commit 6df9cf6

341 files changed

Lines changed: 8438 additions & 8442 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

atom/extra/asio/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ set(ASIO_SOURCES
9595
concurrency/memory_manager.hpp
9696
concurrency/concurrency.hpp
9797
concurrency/concurrency.cpp
98-
98+
9999
# Enhanced MQTT implementation
100100
mqtt/client.cpp
101101
mqtt/client.hpp
102102
mqtt/packet.cpp
103103
mqtt/packet.hpp
104104
mqtt/protocol.hpp
105105
mqtt/types.hpp
106-
106+
107107
# Enhanced SSE implementation
108108
sse/event.cpp
109109
sse/event.hpp
@@ -126,7 +126,7 @@ set(ASIO_SOURCES
126126
sse/server/server.hpp
127127
sse/server/server_config.cpp
128128
sse/server/server_config.hpp
129-
129+
130130
# Core compatibility layer
131131
asio_compatibility.hpp
132132
)
@@ -191,20 +191,20 @@ endif()
191191
option(ATOM_ASIO_BUILD_TESTS "Build ASIO tests" OFF)
192192
if(ATOM_ASIO_BUILD_TESTS)
193193
find_package(GTest REQUIRED)
194-
194+
195195
add_executable(atom-asio-tests
196196
mqtt/test_client.hpp
197197
mqtt/test_packet.hpp
198198
mqtt/test_protocol.hpp
199199
mqtt/test_types.hpp
200200
)
201-
201+
202202
target_link_libraries(atom-asio-tests
203203
PRIVATE
204204
atom-asio-advanced
205205
GTest::gtest_main
206206
)
207-
207+
208208
# Enable testing
209209
enable_testing()
210210
add_test(NAME AsioTests COMMAND atom-asio-tests)
@@ -214,13 +214,13 @@ endif()
214214
option(ATOM_ASIO_BUILD_BENCHMARKS "Build ASIO benchmarks" OFF)
215215
if(ATOM_ASIO_BUILD_BENCHMARKS)
216216
find_package(benchmark REQUIRED)
217-
217+
218218
add_executable(atom-asio-benchmarks
219219
benchmarks/mqtt_benchmark.cpp
220220
benchmarks/sse_benchmark.cpp
221221
benchmarks/concurrency_benchmark.cpp
222222
)
223-
223+
224224
target_link_libraries(atom-asio-benchmarks
225225
PRIVATE
226226
atom-asio-advanced

atom/extra/asio/concurrency/adaptive_spinlock.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ namespace atom::extra::asio::concurrency {
1515

1616
/**
1717
* @brief Adaptive spinlock with exponential backoff for optimal performance
18-
*
18+
*
1919
* This spinlock implementation adapts its behavior based on contention levels,
2020
* using CPU pause instructions for short waits and yielding for longer waits.
2121
*/
2222
class adaptive_spinlock {
2323
private:
2424
cache_aligned<std::atomic<bool>> locked_{false};
25-
25+
2626
// Backoff parameters
2727
static constexpr std::size_t initial_pause_count = 4;
2828
static constexpr std::size_t max_pause_count = 64;
@@ -34,7 +34,7 @@ class adaptive_spinlock {
3434
* @brief Construct an unlocked adaptive spinlock
3535
*/
3636
adaptive_spinlock() = default;
37-
37+
3838
// Non-copyable, non-movable
3939
adaptive_spinlock(const adaptive_spinlock&) = delete;
4040
adaptive_spinlock& operator=(const adaptive_spinlock&) = delete;
@@ -47,7 +47,7 @@ class adaptive_spinlock {
4747
void lock() noexcept {
4848
std::size_t pause_count = initial_pause_count;
4949
std::size_t iteration = 0;
50-
50+
5151
while (true) {
5252
// Fast path: try to acquire immediately
5353
if (!locked_.get().exchange(true, std::memory_order_acquire)) {
@@ -56,14 +56,14 @@ class adaptive_spinlock {
5656
}
5757
return;
5858
}
59-
59+
6060
// Adaptive backoff strategy
6161
if (iteration < yield_threshold) {
6262
// Phase 1: CPU pause with exponential backoff
6363
for (std::size_t i = 0; i < pause_count; ++i) {
6464
cpu_pause();
6565
}
66-
66+
6767
// Exponential backoff up to maximum
6868
if (pause_count < max_pause_count) {
6969
pause_count *= 2;
@@ -74,12 +74,12 @@ class adaptive_spinlock {
7474
} else {
7575
// Phase 3: Brief sleep for heavily contended locks
7676
std::this_thread::sleep_for(sleep_threshold);
77-
77+
7878
if (iteration % 1000 == 0) {
7979
spdlog::warn("Adaptive spinlock heavily contended, iteration: {}", iteration);
8080
}
8181
}
82-
82+
8383
++iteration;
8484
}
8585
}
@@ -144,14 +144,14 @@ class adaptive_lock_guard {
144144

145145
/**
146146
* @brief Reader-writer spinlock with priority inheritance
147-
*
147+
*
148148
* Optimized for scenarios with many readers and few writers,
149149
* providing excellent read performance while ensuring writer fairness.
150150
*/
151151
class reader_writer_spinlock {
152152
private:
153153
cache_aligned<std::atomic<std::int32_t>> state_{0};
154-
154+
155155
// State encoding: positive = reader count, -1 = writer, 0 = unlocked
156156
static constexpr std::int32_t writer_flag = -1;
157157
static constexpr std::int32_t max_readers = std::numeric_limits<std::int32_t>::max();
@@ -173,26 +173,26 @@ class reader_writer_spinlock {
173173
*/
174174
void lock_shared() noexcept {
175175
std::size_t iteration = 0;
176-
176+
177177
while (true) {
178178
std::int32_t current = state_.get().load(std::memory_order_acquire);
179-
179+
180180
// Can acquire read lock if no writer and not at max readers
181181
if (current >= 0 && current < max_readers) {
182-
if (state_.get().compare_exchange_weak(current, current + 1,
182+
if (state_.get().compare_exchange_weak(current, current + 1,
183183
std::memory_order_acquire)) {
184184
spdlog::trace("Reader lock acquired, reader count: {}", current + 1);
185185
return;
186186
}
187187
}
188-
188+
189189
// Adaptive backoff for readers
190190
if (iteration < 32) {
191191
cpu_pause();
192192
} else {
193193
std::this_thread::yield();
194194
}
195-
195+
196196
++iteration;
197197
}
198198
}
@@ -210,15 +210,15 @@ class reader_writer_spinlock {
210210
*/
211211
void lock() noexcept {
212212
std::size_t iteration = 0;
213-
213+
214214
while (true) {
215215
std::int32_t expected = 0;
216-
if (state_.get().compare_exchange_weak(expected, writer_flag,
216+
if (state_.get().compare_exchange_weak(expected, writer_flag,
217217
std::memory_order_acquire)) {
218218
spdlog::trace("Writer lock acquired");
219219
return;
220220
}
221-
221+
222222
// Adaptive backoff for writers
223223
if (iteration < 16) {
224224
cpu_pause();
@@ -227,7 +227,7 @@ class reader_writer_spinlock {
227227
} else {
228228
std::this_thread::sleep_for(std::chrono::microseconds(1));
229229
}
230-
230+
231231
++iteration;
232232
}
233233
}
@@ -245,12 +245,12 @@ class reader_writer_spinlock {
245245
*/
246246
bool try_lock_shared() noexcept {
247247
std::int32_t current = state_.get().load(std::memory_order_acquire);
248-
248+
249249
if (current >= 0 && current < max_readers) {
250-
return state_.get().compare_exchange_strong(current, current + 1,
250+
return state_.get().compare_exchange_strong(current, current + 1,
251251
std::memory_order_acquire);
252252
}
253-
253+
254254
return false;
255255
}
256256

@@ -259,7 +259,7 @@ class reader_writer_spinlock {
259259
*/
260260
bool try_lock() noexcept {
261261
std::int32_t expected = 0;
262-
return state_.get().compare_exchange_strong(expected, writer_flag,
262+
return state_.get().compare_exchange_strong(expected, writer_flag,
263263
std::memory_order_acquire);
264264
}
265265
};

atom/extra/asio/concurrency/concurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace atom::extra::asio::concurrency {
66
std::unique_ptr<concurrency_manager> concurrency_manager::instance_;
77
std::once_flag concurrency_manager::init_flag_;
88

9-
// Static member definitions for memory_manager
9+
// Static member definitions for memory_manager
1010
std::unique_ptr<memory_manager> memory_manager::instance_;
1111
std::once_flag memory_manager::init_flag_;
1212

atom/extra/asio/concurrency/concurrency.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @file concurrency.hpp
55
* @brief Comprehensive concurrency framework with cutting-edge C++23 primitives
6-
*
6+
*
77
* This header provides access to all advanced concurrency components:
88
* - Lock-free data structures with hazard pointers
99
* - Adaptive synchronization primitives
@@ -56,14 +56,14 @@ class concurrent_object_pool {
5656
spdlog::trace("Object acquired from pool");
5757
return std::move(obj.value());
5858
}
59-
59+
6060
// Allocate new object
6161
auto* raw_ptr = memory_pool_.allocate(std::forward<Args>(args)...);
6262
auto obj = std::unique_ptr<T>(raw_ptr);
63-
63+
6464
total_allocated_.get().fetch_add(1, std::memory_order_relaxed);
6565
total_in_use_.get().fetch_add(1, std::memory_order_relaxed);
66-
66+
6767
spdlog::trace("New object allocated for pool");
6868
return obj;
6969
}
@@ -104,7 +104,7 @@ class concurrency_manager {
104104
private:
105105
std::unique_ptr<work_stealing_thread_pool> thread_pool_;
106106
performance_monitor& perf_monitor_;
107-
107+
108108
// Singleton instance
109109
static std::unique_ptr<concurrency_manager> instance_;
110110
static std::once_flag init_flag_;
@@ -113,9 +113,9 @@ class concurrency_manager {
113113
// Initialize with optimal thread count
114114
auto thread_count = std::thread::hardware_concurrency();
115115
if (thread_count == 0) thread_count = 4;
116-
116+
117117
thread_pool_ = std::make_unique<work_stealing_thread_pool>(thread_count);
118-
118+
119119
spdlog::info("Concurrency manager initialized with {} threads", thread_count);
120120
}
121121

@@ -169,9 +169,9 @@ class concurrency_manager {
169169
spdlog::info("Thread pool size: {}", thread_pool_->size());
170170
spdlog::info("Pending tasks: {}", thread_pool_->pending_tasks());
171171
spdlog::info("Performance counters: {}", perf_monitor_.counter_count());
172-
172+
173173
perf_monitor_.log_statistics();
174-
174+
175175
spdlog::info("====================================");
176176
}
177177
};

0 commit comments

Comments
 (0)