Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
c_bind.cpp
Go to the documentation of this file.
1#include "./c_bind.hpp"
2#include "./mem.hpp"
3#include "./serialize.hpp"
4#include "./timer.hpp"
5#include <algorithm>
6
7#ifndef NO_MULTITHREADING
8#include <thread>
9
11 std::atomic<uint32_t> counter = 0;
12 size_t iterations = 0;
13};
14
16{
17 Timer t;
18 // info("thread start with counter at: ", static_cast<size_t>(v->counter));
19 std::vector<uint8_t> data(1024);
20 for (size_t i = 0; i < v->iterations; ++i) {
21 // Do some meaningless work.
22 std::for_each(data.begin(), data.end(), [](auto& i) { i = i & 0x80; });
23 std::for_each(data.begin(), data.end(), [](auto& i) { i = i | 0x01; });
24 std::for_each(data.begin(), data.end(), [](auto& i) { i = static_cast<uint8_t>(i << 3); });
25 (v->counter)++;
26 }
27 // info("thread end with counter at: ", static_cast<size_t>(v->counter), " ", t.seconds(), "s");
28}
29
30void thread_test_abort_entry_point(void* /*unused*/)
31{
32 info("thread_test_abort aborting");
33 std::abort();
34}
35
36WASM_EXPORT void test_threads(uint32_t const* thread_num, uint32_t const* iterations, uint32_t* out)
37{
38 info("test starting...");
39 Timer t;
40 size_t NUM_THREADS = ntohl(*thread_num);
41 std::vector<std::thread> threads(NUM_THREADS);
42 test_threads_data test_data;
43 test_data.iterations = ntohl(*iterations) / NUM_THREADS;
44
45 for (size_t i = 0; i < NUM_THREADS; i++) {
46 threads[i] = std::thread(thread_test_entry_point, &test_data);
47 }
48
49 info("joining...");
50 for (size_t i = 0; i < NUM_THREADS; i++) {
51 threads[i].join();
52 }
53
54 info("test complete with counter at: ", static_cast<size_t>(test_data.counter), " ", t.seconds(), "s");
55 *out = htonl(test_data.counter);
56}
57
59{
60 std::thread thread(thread_test_abort_entry_point, (void*)nullptr);
61 thread.join();
62}
63
65{
66 info("test_abort aborting");
67 std::abort();
68}
69
70#endif
71
73{
74 // refactoring our file access methods to fix this warning is not worth it!
75 // NOLINTBEGIN(cppcoreguidelines-pro-type-vararg)
76 static_cast<void>(fprintf(stdout, "c: hello stdout!"));
77 static_cast<void>(fflush(stdout));
78 static_cast<void>(fprintf(stderr, "c: hello stderr!"));
79 // NOLINTEND(cppcoreguidelines-pro-type-vararg)
80 std::cout << "c++: hello stdout!" << std::flush;
81 std::cerr << "c++: hello stderr!";
82}
Get the execution between a block of code.
Definition timer.hpp:12
double seconds() const
Return the number of seconds elapsed since the start of the timer.
Definition timer.hpp:70
void thread_test_abort_entry_point(void *)
Definition c_bind.cpp:30
WASM_EXPORT void test_threads(uint32_t const *thread_num, uint32_t const *iterations, uint32_t *out)
Definition c_bind.cpp:36
WASM_EXPORT void test_stdout_stderr()
Definition c_bind.cpp:72
void thread_test_entry_point(test_threads_data *v)
Definition c_bind.cpp:15
WASM_EXPORT void test_thread_abort()
Definition c_bind.cpp:58
WASM_EXPORT void test_abort()
Definition c_bind.cpp:64
void info(Args... args)
Definition log.hpp:75
const std::vector< MemoryValue > data
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
size_t iterations
Definition c_bind.cpp:12
std::atomic< uint32_t > counter
Definition c_bind.cpp:11
#define WASM_EXPORT