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

feat(stonedb): formate code with clang-format (#7) #8

Merged
merged 1 commit into from
Jun 16, 2022
Merged
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
49 changes: 19 additions & 30 deletions storage/stonedb/async_tests/main.cc
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ class TaskRunner {
~MyTask() noexcept override {}

void run() noexcept override {
stonedb::base::print("Established task on cpu %3d\n",
stonedb::base::engine().cpu_id());
stonedb::base::print("Established task on cpu %3d\n", stonedb::base::engine().cpu_id());
for (int index = 0; index < _count; ++index) {
for (int jndex = 0; jndex < index; ++jndex) {
*_result += jndex;
@@ -48,8 +47,7 @@ class TaskRunner {

stonedb::base::future<> Run() {
return stonedb::base::sleep(std::chrono::milliseconds(1)).then([this]() {
stonedb::base::print("Established task on cpu %3d\n",
stonedb::base::engine().cpu_id());
stonedb::base::print("Established task on cpu %3d\n", stonedb::base::engine().cpu_id());
uint64_t count = 0;
for (int index = 0; index < _count; ++index) {
for (int jndex = 0; jndex < index; ++jndex) {
@@ -63,8 +61,7 @@ class TaskRunner {
}

stonedb::base::future<uint64_t> get_result() {
stonedb::base::print("Requests on cpu %2d: %ld\n",
stonedb::base::engine().cpu_id(), _result);
stonedb::base::print("Requests on cpu %2d: %ld\n", stonedb::base::engine().cpu_id(), _result);
return stonedb::base::make_ready_future<uint64_t>(_result);
}

@@ -96,21 +93,18 @@ stonedb::base::future<bool> RecurseFuture(int *count) {
// return sleep(1ms).then([count]{ return RecurseFuture(count); });
}

stonedb::base::future<stdexp::optional<bool>> Recurse(
std::shared_ptr<int> counter, unsigned thd) {
stonedb::base::future<stdexp::optional<bool>> Recurse(std::shared_ptr<int> counter, unsigned thd) {
if (*counter == 0) {
return stonedb::base::make_ready_future<stdexp::optional<bool>>(true);
}

int count = (*counter)--;
return stonedb::base::smp::submit_to(
thd,
[count, thd] {
// std::this_thread::sleep_for(1000ms);
stonedb::base::print("Calling on : %d thread counter: %d\n", thd,
count);
test_pool(50000, false);
})
return stonedb::base::smp::submit_to(thd,
[count, thd] {
// std::this_thread::sleep_for(1000ms);
stonedb::base::print("Calling on : %d thread counter: %d\n", thd, count);
test_pool(50000, false);
})
.then([thd]() {
stonedb::base::print("Called completed on : %d thread \n", thd);
return stdexp::optional<bool>(stdexp::nullopt);
@@ -119,8 +113,7 @@ stonedb::base::future<stdexp::optional<bool>> Recurse(

void TestPostTask(std::shared_ptr<core::TaskExecutor> task_executor) {
std::chrono::duration<double> total_elapsed =
stonedb::base::steady_clock_type::now() -
stonedb::base::steady_clock_type::now();
stonedb::base::steady_clock_type::now() - stonedb::base::steady_clock_type::now();
std::chrono::duration<double> max_elapsed = total_elapsed;
for (int index = 0; index < 100000; ++index) {
auto started = stonedb::base::steady_clock_type::now();
@@ -136,22 +129,19 @@ void TestPostTask(std::shared_ptr<core::TaskExecutor> task_executor) {

auto ave_secs = static_cast<double>(total_elapsed.count() / 100000.0);
auto max_secs = static_cast<double>(max_elapsed.count());
stonedb::base::print("Ave post task time: %fs max post time:%fs\n", ave_secs,
max_secs);
stonedb::base::print("Ave post task time: %fs max post time:%fs\n", ave_secs, max_secs);
}

void TestSubmit(std::shared_ptr<core::TaskExecutor> task_executor) {
auto ready_future = task_executor->Execute([]() {
std::shared_ptr<int> counter(new int(10));
stonedb::base::future<> parallel_future = stonedb::base::parallel_for_each(
boost::irange<unsigned>(0, stonedb::base::smp::count),
[counter](unsigned c) {
return stonedb::base::repeat_until_value(
std::bind(&Recurse, counter, c))
.then([](bool) { stonedb::base::print("Repeat completed\n"); });
stonedb::base::future<> parallel_future =
stonedb::base::parallel_for_each(boost::irange<unsigned>(0, stonedb::base::smp::count), [counter](unsigned c) {
return stonedb::base::repeat_until_value(std::bind(&Recurse, counter, c)).then([](bool) {
stonedb::base::print("Repeat completed\n");
});
});
return parallel_future.then(
[]() { stonedb::base::print("Parallel completed\n"); });
return parallel_future.then([]() { stonedb::base::print("Parallel completed\n"); });
});

ready_future.wait();
@@ -176,8 +166,7 @@ void TestSubmitRandom(std::shared_ptr<core::TaskExecutor> task_executor) {
int main(int argc, char **argv) {
auto started = stonedb::base::steady_clock_type::now();
std::shared_ptr<core::TaskExecutor> task_executor(new core::TaskExecutor);
std::future<void> ready_future =
task_executor->Init(std::thread::hardware_concurrency());
std::future<void> ready_future = task_executor->Init(std::thread::hardware_concurrency());
ready_future.wait();
auto elapsed = stonedb::base::steady_clock_type::now() - started;
auto secs = static_cast<double>(elapsed.count() / 1000000000.0);
2 changes: 1 addition & 1 deletion storage/stonedb/base/core/scollectd.h
Original file line number Diff line number Diff line change
@@ -682,7 +682,7 @@ class values_impl : public value_list {

void add_polled(const type_instance_id &, const shared_ptr<value_list> &, bool enabled = true);

using notify_function = std::function<void()> ;
using notify_function = std::function<void()>;
template <typename... _Args>
static auto make_type_instance(description d, _Args &&...args)
-> values_impl<decltype(value<_Args>(std::forward<_Args>(args)))...> {
38 changes: 20 additions & 18 deletions storage/stonedb/base/fmt/format.cpp
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ int safe_strerror(int error_code, char *&buffer, std::size_t buffer_size) FMT_NO

void format_error_code(Writer &out, int error_code, StringRef message) FMT_NOEXCEPT {
// Report error code making sure that the output fits into
// INLINE_BUFFER_SIZE to avoid dynamic memory allocation and potential
// enumInlineBuffer::INLINE_BUFFER_SIZE to avoid dynamic memory allocation and potential
// bad_alloc.
out.clear();
static const char SEP[] = ": ";
@@ -189,9 +189,10 @@ void format_error_code(Writer &out, int error_code, StringRef message) FMT_NOEXC
++error_code_size;
}
error_code_size += internal::count_digits(abs_value);
if (message.size() <= internal::INLINE_BUFFER_SIZE - error_code_size) out << message << SEP;
if (message.size() <= static_cast<size_t>(internal::enumInlineBuffer::INLINE_BUFFER_SIZE) - error_code_size)
out << message << SEP;
out << ERROR_STR << error_code;
assert(out.size() <= internal::INLINE_BUFFER_SIZE);
assert(out.size() <= static_cast<size_t>(internal::enumInlineBuffer::INLINE_BUFFER_SIZE));
}

void report_error(FormatFunc func, int error_code, StringRef message) FMT_NOEXCEPT {
@@ -314,8 +315,8 @@ FMT_FUNC void WindowsError::init(int err_code, CStringRef format_str, ArgList ar

FMT_FUNC void internal::format_windows_error(Writer &out, int error_code, StringRef message) FMT_NOEXCEPT {
FMT_TRY {
MemoryBuffer<wchar_t, INLINE_BUFFER_SIZE> buffer;
buffer.resize(INLINE_BUFFER_SIZE);
MemoryBuffer<wchar_t, enumInlineBuffer::INLINE_BUFFER_SIZE> buffer;
buffer.resize(enumInlineBuffer::INLINE_BUFFER_SIZE);
for (;;) {
wchar_t *system_message = &buffer[0];
int result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FMT_NULL, error_code,
@@ -341,8 +342,8 @@ FMT_FUNC void internal::format_windows_error(Writer &out, int error_code, String

FMT_FUNC void format_system_error(Writer &out, int error_code, StringRef message) FMT_NOEXCEPT {
FMT_TRY {
internal::MemoryBuffer<char, internal::INLINE_BUFFER_SIZE> buffer;
buffer.resize(internal::INLINE_BUFFER_SIZE);
internal::MemoryBuffer<char, static_cast<size_t>(internal::enumInlineBuffer::INLINE_BUFFER_SIZE)> buffer;
buffer.resize(static_cast<size_t>(internal::enumInlineBuffer::INLINE_BUFFER_SIZE));
for (;;) {
char *system_message = &buffer[0];
int result = safe_strerror(error_code, system_message, buffer.size());
@@ -363,14 +364,15 @@ void internal::ArgMap<Char>::init(const ArgList &args) {
if (!map_.empty()) return;
using NamedArg = internal::NamedArg<Char>;
const NamedArg *named_arg = FMT_NULL;
bool use_values = args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
bool use_values =
args.type(static_cast<unsigned>(ArgList::enumMaxPacked::MAX_PACKED_ARGS) - 1) == internal::Arg::Type::NONE;
if (use_values) {
for (unsigned i = 0; /*nothing*/; ++i) {
internal::Arg::Type arg_type = args.type(i);
switch (arg_type) {
case internal::Arg::NONE:
case internal::Arg::Type::NONE:
return;
case internal::Arg::NAMED_ARG:
case internal::Arg::Type::NAMED_ARG:
named_arg = static_cast<const NamedArg *>(args.values_[i].pointer);
map_.push_back(Pair(named_arg->name, *named_arg));
break;
@@ -380,18 +382,18 @@ void internal::ArgMap<Char>::init(const ArgList &args) {
}
return;
}
for (unsigned i = 0; i != ArgList::MAX_PACKED_ARGS; ++i) {
for (unsigned i = 0; i != static_cast<unsigned>(ArgList::enumMaxPacked::MAX_PACKED_ARGS); ++i) {
internal::Arg::Type arg_type = args.type(i);
if (arg_type == internal::Arg::NAMED_ARG) {
if (arg_type == internal::Arg::Type::NAMED_ARG) {
named_arg = static_cast<const NamedArg *>(args.args_[i].pointer);
map_.push_back(Pair(named_arg->name, *named_arg));
}
}
for (unsigned i = ArgList::MAX_PACKED_ARGS; /*nothing*/; ++i) {
for (unsigned i = static_cast<unsigned>(ArgList::enumMaxPacked::MAX_PACKED_ARGS); /*nothing*/; ++i) {
switch (args.args_[i].type) {
case internal::Arg::NONE:
case internal::Arg::Type::NONE:
return;
case internal::Arg::NAMED_ARG:
case internal::Arg::Type::NAMED_ARG:
named_arg = static_cast<const NamedArg *>(args.args_[i].pointer);
map_.push_back(Pair(named_arg->name, *named_arg));
break;
@@ -409,10 +411,10 @@ void internal::FixedBuffer<Char>::grow(std::size_t) {
FMT_FUNC internal::Arg internal::FormatterBase::do_get_arg(unsigned arg_index, const char *&error) {
internal::Arg arg = args_[arg_index];
switch (arg.type) {
case internal::Arg::NONE:
case internal::Arg::Type::NONE:
error = "argument index out of range";
break;
case internal::Arg::NAMED_ARG:
case internal::Arg::Type::NAMED_ARG:
arg = *static_cast<const internal::Arg *>(arg.pointer);
break;
default:
@@ -443,7 +445,7 @@ FMT_FUNC void print(CStringRef format_str, ArgList args) { print(stdout, format_

FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) {
char escape[] = "\x1b[30m";
escape[3] = static_cast<char>('0' + c);
escape[3] = static_cast<char>('0' + static_cast<int>(c));
std::fputs(escape, stdout);
print(format, args);
std::fputs(RESET_COLOR, stdout);
Loading