mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
renamed raii_thread to joining_thread
This commit is contained in:
parent
4d9bc1868d
commit
8a3a431d7e
@ -36,40 +36,40 @@
|
|||||||
namespace gsl
|
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:
|
public:
|
||||||
raii_thread() noexcept = default;
|
joining_thread() noexcept = default;
|
||||||
|
|
||||||
raii_thread(raii_thread const&) = delete;
|
joining_thread(joining_thread const&) = delete;
|
||||||
raii_thread(raii_thread&& other) : t(std::move(other.t)) {}
|
joining_thread(joining_thread&& other) : t(std::move(other.t)) {}
|
||||||
|
|
||||||
raii_thread(std::thread const&) = delete;
|
joining_thread(std::thread const&) = delete;
|
||||||
raii_thread(std::thread&& other) noexcept : t(std::move(other)) {}
|
joining_thread(std::thread&& other) noexcept : t(std::move(other)) {}
|
||||||
|
|
||||||
raii_thread& operator=(raii_thread const&) = delete;
|
joining_thread& operator=(joining_thread const&) = delete;
|
||||||
raii_thread& operator=(raii_thread&& other) noexcept
|
joining_thread& operator=(joining_thread&& other) noexcept
|
||||||
{
|
{
|
||||||
t = std::move(other.t);
|
t = std::move(other.t);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
raii_thread& operator=(std::thread const&) = delete;
|
joining_thread& operator=(std::thread const&) = delete;
|
||||||
raii_thread& operator=(std::thread&& other) noexcept
|
joining_thread& operator=(std::thread&& other) noexcept
|
||||||
{
|
{
|
||||||
t = std::move(other);
|
t = std::move(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Callable, typename... Args>
|
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)...)
|
: 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(); }
|
bool joinable() const { return t.joinable(); }
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
|
|
||||||
void join() { t.join(); }
|
void join() { t.join(); }
|
||||||
|
|
||||||
void swap(raii_thread& other) noexcept
|
void swap(joining_thread& other) noexcept
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(t, other.t);
|
swap(t, other.t);
|
||||||
@ -89,7 +89,7 @@ private:
|
|||||||
std::thread t;
|
std::thread t;
|
||||||
};
|
};
|
||||||
|
|
||||||
void swap(raii_thread& t1, raii_thread& t2) noexcept
|
void swap(joining_thread& t1, joining_thread& t2) noexcept
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(t1.t, t2.t);
|
swap(t1.t, t2.t);
|
||||||
|
@ -34,7 +34,7 @@ SUITE(raii_thread_tests)
|
|||||||
{
|
{
|
||||||
auto start_time = steady_clock::now();
|
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();
|
auto end_time = steady_clock::now();
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ SUITE(raii_thread_tests)
|
|||||||
auto start_time = steady_clock::now();
|
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();
|
auto end_time = steady_clock::now();
|
||||||
@ -58,10 +58,10 @@ SUITE(raii_thread_tests)
|
|||||||
{
|
{
|
||||||
auto start_time = steady_clock::now();
|
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();
|
auto end_time = steady_clock::now();
|
||||||
@ -73,10 +73,10 @@ SUITE(raii_thread_tests)
|
|||||||
{
|
{
|
||||||
auto start_time = steady_clock::now();
|
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);
|
t2 = std::move(t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ SUITE(raii_thread_tests)
|
|||||||
std::thread t1{[&]{ sleep_for(t_100ms); }};
|
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();
|
auto end_time = steady_clock::now();
|
||||||
@ -107,7 +107,7 @@ SUITE(raii_thread_tests)
|
|||||||
std::thread t1{[&]{ sleep_for(t_100ms); }};
|
std::thread t1{[&]{ sleep_for(t_100ms); }};
|
||||||
|
|
||||||
{
|
{
|
||||||
gsl::raii_thread t2;
|
gsl::joining_thread t2;
|
||||||
t2 = std::move(t1);
|
t2 = std::move(t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +118,8 @@ SUITE(raii_thread_tests)
|
|||||||
|
|
||||||
TEST(raii_thread_swap_test)
|
TEST(raii_thread_swap_test)
|
||||||
{
|
{
|
||||||
gsl::raii_thread t1{[&]{ sleep_for(t_100ms); }};
|
gsl::joining_thread t1{[&]{ sleep_for(t_100ms); }};
|
||||||
gsl::raii_thread t2{[&]{ sleep_for(t_100ms); }};
|
gsl::joining_thread t2{[&]{ sleep_for(t_100ms); }};
|
||||||
|
|
||||||
auto id1 = t1.get_id();
|
auto id1 = t1.get_id();
|
||||||
auto id2 = t2.get_id();
|
auto id2 = t2.get_id();
|
||||||
|
Loading…
Reference in New Issue
Block a user