mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Applied clang-format -i -style=file -assume-filename=cpp
include/gsl/gsl_thread
This commit is contained in:
parent
a19d1b0964
commit
74a7ed4bc1
@ -47,17 +47,32 @@ public:
|
|||||||
detached_thread(detached_thread&& other) : t(std::move(other.t)) {}
|
detached_thread(detached_thread&& other) : t(std::move(other.t)) {}
|
||||||
|
|
||||||
detached_thread(std::thread const&) = delete;
|
detached_thread(std::thread const&) = delete;
|
||||||
detached_thread(std::thread&& other) noexcept: t(std::move(other)) { if(t.joinable()) t.detach(); }
|
detached_thread(std::thread&& other) noexcept : t(std::move(other))
|
||||||
|
{
|
||||||
|
if (t.joinable()) t.detach();
|
||||||
|
}
|
||||||
|
|
||||||
detached_thread& operator=(detached_thread const&) = delete;
|
detached_thread& operator=(detached_thread const&) = delete;
|
||||||
detached_thread& operator=(detached_thread&& other) noexcept { t = std::move(other.t); return *this; }
|
detached_thread& operator=(detached_thread&& other) noexcept
|
||||||
|
{
|
||||||
|
t = std::move(other.t);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
detached_thread& operator=(std::thread const&) = delete;
|
detached_thread& operator=(std::thread const&) = delete;
|
||||||
detached_thread& operator=(std::thread&& other) noexcept { t = std::move(other); if(t.joinable()) t.detach(); return *this; }
|
detached_thread& operator=(std::thread&& other) noexcept
|
||||||
|
{
|
||||||
|
t = std::move(other);
|
||||||
|
if (t.joinable()) t.detach();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Callable, typename... Args>
|
template <typename Callable, typename... Args>
|
||||||
explicit detached_thread(Callable&& f, Args&&... args)
|
explicit detached_thread(Callable&& f, Args&&... args)
|
||||||
: t(std::forward<Callable>(f), std::forward<Args>(args)...) { t.detach(); }
|
: t(std::forward<Callable>(f), std::forward<Args>(args)...)
|
||||||
|
{
|
||||||
|
t.detach();
|
||||||
|
}
|
||||||
|
|
||||||
bool joinable() const { return t.joinable(); }
|
bool joinable() const { return t.joinable(); }
|
||||||
|
|
||||||
@ -67,7 +82,11 @@ public:
|
|||||||
|
|
||||||
void join() { t.join(); }
|
void join() { t.join(); }
|
||||||
|
|
||||||
void swap(detached_thread& other) noexcept { using std::swap; swap(t, other.t); }
|
void swap(detached_thread& other) noexcept
|
||||||
|
{
|
||||||
|
using std::swap;
|
||||||
|
swap(t, other.t);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread t;
|
std::thread t;
|
||||||
@ -93,16 +112,29 @@ public:
|
|||||||
raii_thread(std::thread&& other) noexcept : t(std::move(other)) {}
|
raii_thread(std::thread&& other) noexcept : t(std::move(other)) {}
|
||||||
|
|
||||||
raii_thread& operator=(raii_thread const&) = delete;
|
raii_thread& operator=(raii_thread const&) = delete;
|
||||||
raii_thread& operator=(raii_thread&& other) noexcept { t = std::move(other.t); return *this; }
|
raii_thread& operator=(raii_thread&& other) noexcept
|
||||||
|
{
|
||||||
|
t = std::move(other.t);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
raii_thread& operator=(std::thread const&) = delete;
|
raii_thread& operator=(std::thread const&) = delete;
|
||||||
raii_thread& operator=(std::thread&& other) noexcept { t = std::move(other); return *this; }
|
raii_thread& operator=(std::thread&& other) noexcept
|
||||||
|
{
|
||||||
|
t = std::move(other);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Callable, typename... Args>
|
template <typename Callable, typename... Args>
|
||||||
explicit raii_thread(Callable&& f, Args&&... args)
|
explicit raii_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(); }
|
~raii_thread()
|
||||||
|
{
|
||||||
|
if (t.joinable()) t.join();
|
||||||
|
}
|
||||||
|
|
||||||
bool joinable() const { return t.joinable(); }
|
bool joinable() const { return t.joinable(); }
|
||||||
|
|
||||||
@ -112,7 +144,11 @@ public:
|
|||||||
|
|
||||||
void join() { t.join(); }
|
void join() { t.join(); }
|
||||||
|
|
||||||
void swap(raii_thread& other) noexcept { using std::swap; swap(t, other.t); }
|
void swap(raii_thread& other) noexcept
|
||||||
|
{
|
||||||
|
using std::swap;
|
||||||
|
swap(t, other.t);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread t;
|
std::thread t;
|
||||||
|
Loading…
Reference in New Issue
Block a user