]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/fiber/examples/work_sharing.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / fiber / examples / work_sharing.cpp
index 14146ae58c860beafa131cc6b95aaf896c6fdb04..f017d58f55b22385d64f900ca34815315b15880e 100644 (file)
 
 #include <boost/fiber/all.hpp>
 
-#include "barrier.hpp"
+#include "thread_barrier.hpp"
 
 static std::size_t fiber_count{ 0 };
 static std::mutex mtx_count{};
 static boost::fibers::condition_variable_any cnd_count{};
-typedef std::unique_lock< std::mutex > lock_t;
+typedef std::unique_lock< std::mutex > lock_type;
 
 /*****************************************************************************
 *   example fiber function
@@ -49,7 +49,7 @@ void whatevah( char me) {
         }
     } catch ( ... ) {
     }
-    lock_t lk( mtx_count);
+    lock_type lk( mtx_count);
     if ( 0 == --fiber_count) { /*< Decrement fiber counter for each completed fiber. >*/
         lk.unlock();
         cnd_count.notify_all(); /*< Notify all fibers waiting on `cnd_count`. >*/
@@ -61,7 +61,7 @@ void whatevah( char me) {
 *   example thread function
 *****************************************************************************/
 //[thread_fn_ws
-void thread( barrier * b) {
+void thread( thread_barrier * b) {
     std::ostringstream buffer;
     buffer << "thread started " << std::this_thread::get_id() << std::endl;
     std::cout << buffer.str() << std::flush;
@@ -70,7 +70,7 @@ void thread( barrier * b) {
         join the work sharing.
     >*/
     b->wait(); /*< sync with other threads: allow them to start processing >*/
-    lock_t lk( mtx_count);
+    lock_type lk( mtx_count);
     cnd_count.wait( lk, [](){ return 0 == fiber_count; } ); /*<
         Suspend main fiber and resume worker fibers in the meanwhile.
         Main fiber gets resumed (e.g returns from `condition_variable_any::wait()`)
@@ -99,7 +99,7 @@ int main( int argc, char *argv[]) {
         boost::fibers::fiber([c](){ whatevah( c); }).detach();
         ++fiber_count; /*< Increment fiber counter for each new fiber. >*/
     }
-    barrier b( 4);
+    thread_barrier b( 4);
     std::thread threads[] = { /*<
         Launch a couple of threads that join the work sharing.
     >*/
@@ -109,7 +109,7 @@ int main( int argc, char *argv[]) {
     };
     b.wait(); /*< sync with other threads: allow them to start processing >*/
     {
-        lock_t/*< `lock_t` is typedef'ed as __unique_lock__< [@http://en.cppreference.com/w/cpp/thread/mutex `std::mutex`] > >*/ lk( mtx_count);
+        lock_type/*< `lock_type` is typedef'ed as __unique_lock__< [@http://en.cppreference.com/w/cpp/thread/mutex `std::mutex`] > >*/ lk( mtx_count);
         cnd_count.wait( lk, [](){ return 0 == fiber_count; } ); /*<
             Suspend main fiber and resume worker fibers in the meanwhile.
             Main fiber gets resumed (e.g returns from `condition_variable_any::wait()`)