]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/fiber/skynet.cpp
12 #include <boost/fiber/all.hpp>
13 #include <boost/pool/pool.hpp>
14 #include <boost/pool/pool_alloc.hpp>
16 #include "bind/bind_processor.hpp"
18 using clock_type
= std::chrono::steady_clock
;
19 using duration_type
= clock_type::duration
;
20 using time_point_type
= clock_type::time_point
;
21 using channel_type
= boost::fibers::unbounded_channel
< std::uint64_t >;
22 using allocator_type
= boost::fibers::pooled_fixedsize_stack
;
24 void prepare( allocator_type
& salloc
) {
25 auto sctx
= salloc
.allocate();
26 salloc
.deallocate( sctx
);
30 void skynet( allocator_type
& salloc
, channel_type
& c
, std::size_t num
, std::size_t size
, std::size_t div
) {
35 for ( std::size_t i
= 0; i
< div
; ++i
) {
36 auto sub_num
= num
+ i
* size
/ div
;
37 boost::fibers::fiber
{ boost::fibers::launch::dispatch
,
38 std::allocator_arg
, salloc
,
40 std::ref( salloc
), std::ref( rc
), sub_num
, size
/ div
, div
}.detach();
42 std::uint64_t sum
{ 0 };
43 for ( std::size_t i
= 0; i
< div
; ++i
) {
44 sum
+= rc
.value_pop();
52 bind_to_processor( 0);
53 std::size_t stack_size
{ 4048 };
54 std::size_t size
{ 100000 };
55 std::size_t div
{ 10 };
56 allocator_type salloc
{ stack_size
, size
};
58 std::uint64_t result
{ 0 };
59 duration_type duration
{ duration_type::zero() };
61 time_point_type start
{ clock_type::now() };
62 skynet( salloc
, rc
, 0, size
, div
);
63 result
= rc
.value_pop();
64 duration
= clock_type::now() - start
;
65 std::cout
<< "Result: " << result
<< " in " << duration
.count() / 1000000 << " ms" << std::endl
;
66 std::cout
<< "done." << std::endl
;
68 } catch ( std::exception
const& e
) {
69 std::cerr
<< "exception: " << e
.what() << std::endl
;
71 std::cerr
<< "unhandled exception" << std::endl
;