renamed raii_thread to joining_thread

This commit is contained in:
Galik 2017-05-21 18:11:08 +01:00
parent 4d9bc1868d
commit 8a3a431d7e
2 changed files with 25 additions and 25 deletions

View File

@ -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 <typename Callable, typename... Args>
explicit raii_thread(Callable&& f, Args&&... args)
explicit joining_thread(Callable&& f, Args&&... args)
: t(std::forward<Callable>(f), std::forward<Args>(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);

View File

@ -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();