diff --git a/include/gsl/gsl_thread b/include/gsl/gsl_thread index ffc51bd..ba69731 100644 --- a/include/gsl/gsl_thread +++ b/include/gsl/gsl_thread @@ -36,40 +36,40 @@ namespace gsl { -class raii_thread +class joining_thread { - friend void swap(raii_thread& t1, raii_thread& t2) noexcept; + friend void swap(joining_thread& t1, joining_thread& t2) noexcept; public: - raii_thread() noexcept = default; + joining_thread() noexcept = default; - raii_thread(raii_thread const&) = delete; - raii_thread(raii_thread&& other) : t(std::move(other.t)) {} + joining_thread(joining_thread const&) = delete; + joining_thread(joining_thread&& other) : t(std::move(other.t)) {} - raii_thread(std::thread const&) = delete; - raii_thread(std::thread&& other) noexcept : t(std::move(other)) {} + joining_thread(std::thread const&) = delete; + joining_thread(std::thread&& other) noexcept : t(std::move(other)) {} - raii_thread& operator=(raii_thread const&) = delete; - raii_thread& operator=(raii_thread&& other) noexcept + joining_thread& operator=(joining_thread const&) = delete; + joining_thread& operator=(joining_thread&& other) noexcept { t = std::move(other.t); return *this; } - raii_thread& operator=(std::thread const&) = delete; - raii_thread& operator=(std::thread&& other) noexcept + joining_thread& operator=(std::thread const&) = delete; + joining_thread& operator=(std::thread&& other) noexcept { t = std::move(other); return *this; } template - explicit raii_thread(Callable&& f, Args&&... args) + explicit joining_thread(Callable&& f, Args&&... args) : t(std::forward(f), std::forward(args)...) { } - ~raii_thread() { if (t.joinable()) t.join(); } + ~joining_thread() { if (t.joinable()) t.join(); } bool joinable() const { return t.joinable(); } @@ -79,7 +79,7 @@ public: void join() { t.join(); } - void swap(raii_thread& other) noexcept + void swap(joining_thread& other) noexcept { using std::swap; swap(t, other.t); @@ -89,7 +89,7 @@ private: std::thread t; }; -void swap(raii_thread& t1, raii_thread& t2) noexcept +void swap(joining_thread& t1, joining_thread& t2) noexcept { using std::swap; swap(t1.t, t2.t); diff --git a/tests/thread_tests.cpp b/tests/thread_tests.cpp index 4e9dc24..e66154b 100644 --- a/tests/thread_tests.cpp +++ b/tests/thread_tests.cpp @@ -34,7 +34,7 @@ SUITE(raii_thread_tests) { auto start_time = steady_clock::now(); - gsl::raii_thread t{[&]{ sleep_for(t_100ms); }}; + gsl::joining_thread t{[&]{ sleep_for(t_100ms); }}; auto end_time = steady_clock::now(); @@ -46,7 +46,7 @@ SUITE(raii_thread_tests) auto start_time = steady_clock::now(); { - gsl::raii_thread t{[&]{ sleep_for(t_100ms); }}; + gsl::joining_thread t{[&]{ sleep_for(t_100ms); }}; } auto end_time = steady_clock::now(); @@ -58,10 +58,10 @@ SUITE(raii_thread_tests) { auto start_time = steady_clock::now(); - gsl::raii_thread t1{[&]{ sleep_for(t_100ms); }}; + gsl::joining_thread t1{[&]{ sleep_for(t_100ms); }}; { - gsl::raii_thread t2{std::move(t1)}; + gsl::joining_thread t2{std::move(t1)}; } auto end_time = steady_clock::now(); @@ -73,10 +73,10 @@ SUITE(raii_thread_tests) { auto start_time = steady_clock::now(); - gsl::raii_thread t1{[&]{ sleep_for(t_100ms); }}; + gsl::joining_thread t1{[&]{ sleep_for(t_100ms); }}; { - gsl::raii_thread t2; + gsl::joining_thread t2; t2 = std::move(t1); } @@ -92,7 +92,7 @@ SUITE(raii_thread_tests) std::thread t1{[&]{ sleep_for(t_100ms); }}; { - gsl::raii_thread t2{std::move(t1)}; + gsl::joining_thread t2{std::move(t1)}; } auto end_time = steady_clock::now(); @@ -107,7 +107,7 @@ SUITE(raii_thread_tests) std::thread t1{[&]{ sleep_for(t_100ms); }}; { - gsl::raii_thread t2; + gsl::joining_thread t2; t2 = std::move(t1); } @@ -118,8 +118,8 @@ SUITE(raii_thread_tests) TEST(raii_thread_swap_test) { - gsl::raii_thread t1{[&]{ sleep_for(t_100ms); }}; - gsl::raii_thread t2{[&]{ sleep_for(t_100ms); }}; + gsl::joining_thread t1{[&]{ sleep_for(t_100ms); }}; + gsl::joining_thread t2{[&]{ sleep_for(t_100ms); }}; auto id1 = t1.get_id(); auto id2 = t2.get_id();