Apply clang-format across the whole tree
Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs, Allman functions) over every source file so the tree is formatter-clean. Whitespace only -- no behavior change; full x64 + x86 suites pass. Also set SortIncludes: false in .clang-format. Windows include order is load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h / dinput.h; winsock2.h must precede windows.h), and the default alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build break. Leaving order alone keeps the manual, correct grouping.
This commit is contained in:
@@ -18,14 +18,12 @@
|
||||
|
||||
using namespace coop;
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
int g_failures = 0;
|
||||
void check(bool ok, const char* what)
|
||||
{
|
||||
std::printf("%s %s\n", ok ? " ok:" : "FAIL:", what);
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
++g_failures;
|
||||
}
|
||||
}
|
||||
@@ -37,8 +35,7 @@ std::string make_line(unsigned thread, unsigned long long seq)
|
||||
char token[32];
|
||||
std::snprintf(token, sizeof(token), "T%02uS%010llu", thread, seq);
|
||||
std::string s;
|
||||
while (s.size() + std::strlen(token) + 1 < kLogMsgLen - 1)
|
||||
{
|
||||
while (s.size() + std::strlen(token) + 1 < kLogMsgLen - 1) {
|
||||
s += token;
|
||||
s += ' ';
|
||||
}
|
||||
@@ -50,29 +47,20 @@ bool line_consistent(const char* text)
|
||||
{
|
||||
std::string first;
|
||||
std::string cur;
|
||||
for (const char* p = text;; ++p)
|
||||
{
|
||||
if (*p == ' ' || *p == '\0')
|
||||
{
|
||||
if (!cur.empty())
|
||||
{
|
||||
if (first.empty())
|
||||
{
|
||||
for (const char* p = text;; ++p) {
|
||||
if (*p == ' ' || *p == '\0') {
|
||||
if (!cur.empty()) {
|
||||
if (first.empty()) {
|
||||
first = cur;
|
||||
}
|
||||
else if (cur != first)
|
||||
{
|
||||
} else if (cur != first) {
|
||||
return false;
|
||||
}
|
||||
cur.clear();
|
||||
}
|
||||
if (*p == '\0')
|
||||
{
|
||||
if (*p == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
cur.push_back(*p);
|
||||
}
|
||||
}
|
||||
@@ -93,8 +81,7 @@ int main()
|
||||
{
|
||||
auto buf = make_ring(8);
|
||||
auto& ring = *reinterpret_cast<LogRing*>(buf.data());
|
||||
for (unsigned long long n = 0; n < 11; ++n)
|
||||
{
|
||||
for (unsigned long long n = 0; n < 11; ++n) {
|
||||
const std::string line = make_line(0, n);
|
||||
log_ring_push(ring, 1234, LogLevel_Info, n, line.c_str());
|
||||
}
|
||||
@@ -103,8 +90,7 @@ int main()
|
||||
log_ring_drain(ring, cursor, [&](const LogRecord& rec) { got.push_back(rec.text); });
|
||||
check(got.size() == 8, "wrap: drains exactly capacity lines after overflow");
|
||||
bool ordered = true;
|
||||
for (std::size_t k = 0; k < got.size(); ++k)
|
||||
{
|
||||
for (std::size_t k = 0; k < got.size(); ++k) {
|
||||
ordered = ordered && got[k] == make_line(0, 3 + k); // oldest 3 (0,1,2) dropped
|
||||
}
|
||||
check(ordered, "wrap: keeps the newest `capacity` lines, in order, oldest dropped");
|
||||
@@ -119,12 +105,10 @@ int main()
|
||||
std::atomic<bool> stop{false};
|
||||
std::atomic<long long> produced{0};
|
||||
std::vector<std::thread> producers;
|
||||
for (unsigned t = 0; t < 4; ++t)
|
||||
{
|
||||
for (unsigned t = 0; t < 4; ++t) {
|
||||
producers.emplace_back([&, t] {
|
||||
unsigned long long n = 0;
|
||||
while (!stop.load(std::memory_order_relaxed))
|
||||
{
|
||||
while (!stop.load(std::memory_order_relaxed)) {
|
||||
const std::string line = make_line(t, n++);
|
||||
log_ring_push(ring, t, LogLevel_Info, n, line.c_str());
|
||||
produced.fetch_add(1, std::memory_order_relaxed);
|
||||
@@ -139,14 +123,12 @@ int main()
|
||||
auto drain = [&] {
|
||||
log_ring_drain(ring, cursor, [&](const LogRecord& rec) {
|
||||
consumed.fetch_add(1, std::memory_order_relaxed);
|
||||
if (!line_consistent(rec.text))
|
||||
{
|
||||
if (!line_consistent(rec.text)) {
|
||||
torn.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
});
|
||||
};
|
||||
while (!stop.load(std::memory_order_relaxed))
|
||||
{
|
||||
while (!stop.load(std::memory_order_relaxed)) {
|
||||
drain();
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(50)); // fall behind so slots wrap
|
||||
}
|
||||
@@ -155,8 +137,7 @@ int main()
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
stop.store(true, std::memory_order_relaxed);
|
||||
for (auto& p : producers)
|
||||
{
|
||||
for (auto& p : producers) {
|
||||
p.join();
|
||||
}
|
||||
consumer.join();
|
||||
|
||||
Reference in New Issue
Block a user