Skip to content

Commit 3d1bdd6

Browse files
committed
fix: clang-tidy
1 parent 26ba079 commit 3d1bdd6

6 files changed

Lines changed: 16 additions & 10 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test:
4949
## tidy: 🧹 tidy things up before committing code
5050
.PHONY: tidy
5151
tidy:
52-
find src/ tests/ -name '*.cpp' | xargs clang-tidy -p build/Debug --fix --format-style=.clang-format
52+
find src/ -name '*.cpp' | xargs clang-tidy -p build/Debug --fix --format-style=.clang-format
5353
find src/ tests/ \( -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' \) -exec clang-format -i {} +
5454

5555
## build-release: 🔨🔨 compile (prod)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ a proof-of-concept, showcasing some c++ coding combined with some fintech concep
118118
- decimal type
119119
- zeromq + protobufs?
120120
- shellcheck?
121+
- conan build_requires
121122
- deployment
122123
- terraform
123124

hooks/check_clang_tidy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if [ ! -f "$BUILD_DIR/compile_commands.json" ]; then
2020
exit 1
2121
fi
2222

23-
files=$(find "$SCRIPT_DIR"/../src/ "$SCRIPT_DIR"/../tests/ \( -name '*.cpp' -o -name '*.c' \))
23+
files=$(find "$SCRIPT_DIR"/../src/ \( -name '*.cpp' -o -name '*.c' \))
2424
tidy_errors=0
2525
for file in $files; do
2626
echo "Running clang-tidy on $file"

hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313

1414
# Run subscripts
1515
echo "Running strict pre-commit checks on src/ and tests/"
16-
# bash "$DIR/check_clang_tidy.sh"
16+
bash "$DIR/check_clang_tidy.sh"
1717
bash "$DIR/check_clang_format.sh"
1818
echo "✅ Pre-commit checks passed on full codebase."

src/ui/TableApp.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ ftxui::Element orderbookToTable(OrderBook &ob) {
6262
// ─────────── Data Rows ───────────
6363
const std::vector<BidAsk> x = ob.toVector();
6464
constexpr size_t max_rows = 15;
65-
const int rowCount = std::min(x.size(), max_rows);
66-
for (int i = 0; i < rowCount; ++i) {
65+
const size_t rowCount = std::min(x.size(), max_rows);
66+
for (size_t i = 0; i < rowCount; ++i) {
6767
ftxui::Elements cells;
6868
cells.push_back(ftxui::text(Pad(x[i].bid_sz, column_width)));
6969
cells.push_back(ftxui::text(Pad(x[i].bid_px, column_width)));
@@ -122,15 +122,18 @@ void TableApp::pollQueue(const std::stop_token &stoken) {
122122
/// Performs an adaptive backoff by spinning then sleeping, increasing sleep
123123
/// time exponentially. Yield 10x times, followed by a 2x sleep capped at
124124
/// 1ms
125+
constexpr int INITIAL_SLEEP_US = 10;
125126
int spinCount = 0;
126-
int sleepTimeUs = 10;
127+
int sleepTimeUs = INITIAL_SLEEP_US;
127128
auto adaptiveBackoff = [&spinCount, &sleepTimeUs]() {
128-
if (spinCount < 10) {
129+
constexpr int MIN_SPINS = 10;
130+
constexpr int MAX_SLEEP_US = 1000;
131+
if (spinCount < MIN_SPINS) {
129132
++spinCount;
130133
std::this_thread::yield();
131134
} else {
132135
std::this_thread::sleep_for(std::chrono::microseconds(sleepTimeUs));
133-
sleepTimeUs = std::min(sleepTimeUs * 2, 1000);
136+
sleepTimeUs = std::min(sleepTimeUs * 2, MAX_SLEEP_US);
134137
}
135138
};
136139

@@ -161,7 +164,7 @@ void TableApp::pollQueue(const std::stop_token &stoken) {
161164

162165
// Reset backoff state
163166
spinCount = 0;
164-
sleepTimeUs = 10;
167+
sleepTimeUs = INITIAL_SLEEP_US;
165168
}
166169
spdlog::info("closing worker thread...");
167170
}

src/utils/Threading.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
namespace Utils {
1212

13+
constexpr int MAX_STRING_LENGTH = 15;
14+
1315
void Threading::set_thread_name(const std::string &name) {
1416
#if defined(__linux__)
1517
// Linux: Limit is 16 bytes including null terminator
16-
pthread_setname_np(pthread_self(), name.substr(0, 15).c_str());
18+
pthread_setname_np(pthread_self(), name.substr(0, MAX_STRING_LENGTH).c_str());
1719

1820
#elif defined(__APPLE__)
1921
// macOS: Only supports setting name from within the thread

0 commit comments

Comments
 (0)